From bfb8838d5de596d8fc249981146ce1d73fdaefe5 Mon Sep 17 00:00:00 2001 From: Evan Bacon Date: Sat, 5 Aug 2023 15:03:04 -0500 Subject: [PATCH] Create `@config-plugins/apple-settings` plugin (#182) * wip * update repo meta * working demo * updates * add linking * Updated demo more * drop assets * add slider to example * Updated types and usage * add multi value page example --- .github/ISSUE_TEMPLATE/bug_report.yml | 1 + .github/ISSUE_TEMPLATE/config.yml | 2 +- .github/dependabot.yml | 6 + apps/apple-settings/app.config.ts | 137 +++++++ apps/apple-settings/app.json | 6 + apps/apple-settings/index.js | 5 + apps/apple-settings/package.json | 24 ++ apps/apple-settings/src/App.tsx | 57 +++ apps/apple-settings/src/SettingsViews.tsx | 91 +++++ apps/apple-settings/tsconfig.json | 4 + packages/apple-settings/.eslintrc.js | 2 + packages/apple-settings/README.md | 188 +++++++++ .../__mocks__/@expo/image-utils.ts | 8 + packages/apple-settings/__mocks__/fs.ts | 2 + packages/apple-settings/jest.config.js | 12 + packages/apple-settings/jest/setup.js | 2 + packages/apple-settings/package.json | 44 +++ .../apple-settings/src/base-mods/strings.ts | 83 ++++ .../src/base-mods/withSettingsPlist.ts | 87 ++++ .../src/base-mods/withSettingsStrings.ts | 85 ++++ .../src/base-mods/withXcparse.ts | 65 +++ packages/apple-settings/src/index.tsx | 17 + packages/apple-settings/src/models.ts | 256 ++++++++++++ .../src/schema/SettingsPlist.json | 373 ++++++++++++++++++ .../src/schema/SettingsPlist.ts | 274 +++++++++++++ packages/apple-settings/src/static.ts | 140 +++++++ .../src/withLinkedSettingsBundle.ts | 89 +++++ packages/apple-settings/tsconfig.json | 9 + yarn.lock | 233 ++++++++++- 29 files changed, 2297 insertions(+), 5 deletions(-) create mode 100644 apps/apple-settings/app.config.ts create mode 100644 apps/apple-settings/app.json create mode 100644 apps/apple-settings/index.js create mode 100644 apps/apple-settings/package.json create mode 100644 apps/apple-settings/src/App.tsx create mode 100644 apps/apple-settings/src/SettingsViews.tsx create mode 100644 apps/apple-settings/tsconfig.json create mode 100644 packages/apple-settings/.eslintrc.js create mode 100644 packages/apple-settings/README.md create mode 100644 packages/apple-settings/__mocks__/@expo/image-utils.ts create mode 100644 packages/apple-settings/__mocks__/fs.ts create mode 100644 packages/apple-settings/jest.config.js create mode 100644 packages/apple-settings/jest/setup.js create mode 100644 packages/apple-settings/package.json create mode 100644 packages/apple-settings/src/base-mods/strings.ts create mode 100644 packages/apple-settings/src/base-mods/withSettingsPlist.ts create mode 100644 packages/apple-settings/src/base-mods/withSettingsStrings.ts create mode 100644 packages/apple-settings/src/base-mods/withXcparse.ts create mode 100644 packages/apple-settings/src/index.tsx create mode 100644 packages/apple-settings/src/models.ts create mode 100644 packages/apple-settings/src/schema/SettingsPlist.json create mode 100644 packages/apple-settings/src/schema/SettingsPlist.ts create mode 100644 packages/apple-settings/src/static.ts create mode 100644 packages/apple-settings/src/withLinkedSettingsBundle.ts create mode 100644 packages/apple-settings/tsconfig.json diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 650d8b49..f61aba7e 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -30,6 +30,7 @@ body: label: Config Plugin options: - '@config-plugins/android-jsc-intl' + - '@config-plugins/apple-settings' - '@config-plugins/detox' - '@config-plugins/ffmpeg-kit-react-native' - '@config-plugins/ios-stickers' diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 406046c4..8beeb8b1 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -11,7 +11,7 @@ contact_links: url: https://github.com/wix/Detox/issues - about: FFmpeg Kit for React Native name: 📦 ffmpeg-kit-react-native issues - url: https://github.com/tanersener/ffmpeg-kit/issues + url: https://github.com/arthenica/ffmpeg-kit/issues - about: Adjust React Native SDK name: 📦 react-native-adjust issues url: https://github.com/adjust/react_native_sdk/issues diff --git a/.github/dependabot.yml b/.github/dependabot.yml index edcc7905..5827836b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -11,6 +11,12 @@ updates: interval: daily time: '09:00' timezone: America/Los_Angeles + - package-ecosystem: npm + directory: packages/apple-settings + schedule: + interval: daily + time: '09:00' + timezone: America/Los_Angeles - package-ecosystem: npm directory: packages/detox schedule: diff --git a/apps/apple-settings/app.config.ts b/apps/apple-settings/app.config.ts new file mode 100644 index 00000000..91223b2c --- /dev/null +++ b/apps/apple-settings/app.config.ts @@ -0,0 +1,137 @@ +import withAppleSettings, { + ChildPane, + Group, + RadioGroup, + Slider, + Switch, + TextField, + Title, +} from "@config-plugins/apple-settings"; +import { MultiValue } from "@config-plugins/apple-settings/build/models"; +import { ConfigContext, ExpoConfig } from "expo/config"; +import path from "node:path"; + +const folderName = path.basename(__dirname); +const cleanName = folderName.replace(/[_\s-]/g, ""); +const appId = "dev.bacon." + cleanName; + +function withWhiteLabel(config: Partial) { + if (!config.extra) config.extra = {}; + // Expose CI env variables to the app + config.extra.CI = process.env.CI; + + if (!config.ios) config.ios = {}; + config.ios.bundleIdentifier = appId; + if (!config.android) config.android = {}; + config.android.package = appId; + + return config; +} + +module.exports = ({ config }: ConfigContext): Partial => { + config = withWhiteLabel(config); + + config = withAppleSettings(config as ExpoConfig, { + // The name of the .plist file to generate. Root is the default and must be provided. + Root: { + // The locales object is optional. If provided, it will be used to generate the localized .strings files. + locales: { + // The Apple locale code. This will be used to generate the .strings file. + en: { + // Name of the localized key. + Name: "Text Field", + }, + }, + // The page object is required. It will be used to generate the .plist file. + // The contents will be converted directly to plist. + page: { + // The `PreferenceSpecifiers` defines the UI elements to generate. + PreferenceSpecifiers: [ + Title({ + title: "Title", + value: "Default Title", + key: "title_preference", + }), + // Helper models can be used to generate the UI elements using a syntax that's + // similar to React Native. + TextField({ + title: "Name", + key: "name_preference", + value: "", + keyboardType: "Alphabet", + autoCapitalize: "None", + autoCorrect: "No", + }), + Switch({ + title: "Enabled", + key: "enabled_preference", + value: true, + }), + Slider({ + key: "slider_preference", + value: 0.5, + }), + RadioGroup({ + value: "option1", + key: "radio_preference", + items: [ + { + title: "Option 1", + value: "option1", + }, + + { + title: "Option 2", + value: "option2", + }, + ], + }), + MultiValue({ + title: "Multi Value", + key: "multi_value_preference", + value: "alpha", + items: [ + { + title: "Alpha", + value: "alpha", + short: "α", + }, + { + title: "Beta", + value: "beta", + short: "β", + }, + { + title: "Delta", + value: "delta", + short: "Δ", + }, + { + title: "Omega", + value: "omega", + short: "Ω", + }, + ], + }), + + // Child panes can be used to create nested pages. + ChildPane({ + title: "About", + }), + ], + }, + }, + // About page + About: { + page: { + PreferenceSpecifiers: [ + Group({ + title: "About Info", + }), + ], + }, + }, + }); + + return config; +}; diff --git a/apps/apple-settings/app.json b/apps/apple-settings/app.json new file mode 100644 index 00000000..0278571e --- /dev/null +++ b/apps/apple-settings/app.json @@ -0,0 +1,6 @@ +{ + "expo": { + "name": "apple-settings", + "icon": "https://icogen.vercel.app/api/icon?icon=🔌&color_hex=1832BA" + } +} diff --git a/apps/apple-settings/index.js b/apps/apple-settings/index.js new file mode 100644 index 00000000..58298e14 --- /dev/null +++ b/apps/apple-settings/index.js @@ -0,0 +1,5 @@ +import { registerRootComponent } from "expo"; + +import App from "./src/App"; + +registerRootComponent(App); diff --git a/apps/apple-settings/package.json b/apps/apple-settings/package.json new file mode 100644 index 00000000..e326b33f --- /dev/null +++ b/apps/apple-settings/package.json @@ -0,0 +1,24 @@ +{ + "name": "@config-plugins-app/apple-settings", + "main": "./index.js", + "version": "1.0.0", + "scripts": { + "start": "expo start --dev-client", + "ios": "expo run:ios", + "android": "expo run:android" + }, + "dependencies": { + "@config-plugins/ios-stickers": "*", + "@react-native-community/slider": "^4.4.2", + "@react-native-picker/picker": "2.4.10", + "expo": "^49.0.3", + "expo-splash-screen": "~0.20.4", + "expo-status-bar": "~1.6.0", + "react": "18.2.0", + "react-native": "0.72.3" + }, + "devDependencies": { + "@babel/core": "^7.20.0" + }, + "private": true +} diff --git a/apps/apple-settings/src/App.tsx b/apps/apple-settings/src/App.tsx new file mode 100644 index 00000000..67c78cba --- /dev/null +++ b/apps/apple-settings/src/App.tsx @@ -0,0 +1,57 @@ +import React from "react"; +import { Button, Linking, StyleSheet, View } from "react-native"; + +import { + SettingsRadioGroup, + SettingsSlider, + SettingsSwitch, + SettingsTextInput, + SettingsTitle, +} from "./SettingsViews"; + +const App = () => { + return ( + + {/* */} + + + + + + + + + +