-
Notifications
You must be signed in to change notification settings - Fork 37
chore: Add FDv2 example project for react-native. #1277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f44eae2
feat: React Native FDv2 support.
kinyoklion 6f8f006
feat: React Native FDv2 support.
kinyoklion ca00a4f
Refine RN data system options documents.
kinyoklion 21b3f73
fix: expose setConnectionMode publicly with FDv2 overloads as @internal
kinyoklion cf1c166
merge: bring in FDv2 changes from rlamb/react-native-fdv2
kinyoklion fce5b09
Cleanup
kinyoklion 7e00858
Merge branch 'main' into rlamb/react-native-fdv2-example
kinyoklion 3f9c780
Revert client changes.
kinyoklion 0e160ec
PR feedback
kinyoklion 399d6c5
chore: Pin SDK dep in example-fdv2 and register with release-please.
kinyoklion eb84ce4
Merge branch 'main' into rlamb/react-native-fdv2-example
kinyoklion b481295
chore: Address PR feedback on example-fdv2.
kinyoklion c895665
Use workspace version.
kinyoklion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| MOBILE_KEY= | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files | ||
| .env | ||
|
|
||
| # dependencies | ||
| node_modules/ | ||
|
|
||
| # Expo | ||
| .expo/ | ||
| dist/ | ||
| web-build/ | ||
|
|
||
| # Native | ||
| *.orig.* | ||
| *.jks | ||
| *.p8 | ||
| *.p12 | ||
| *.key | ||
| *.mobileprovision | ||
|
|
||
| # Metro | ||
| .metro-health-check* | ||
|
|
||
| # debug | ||
| npm-debug.* | ||
| yarn-debug.* | ||
| yarn-error.* | ||
|
|
||
| # macOS | ||
| .DS_Store | ||
| *.pem | ||
|
|
||
| # local env files | ||
| .env*.local | ||
|
|
||
| # typescript | ||
| *.tsbuildinfo | ||
|
|
||
| ios | ||
| android | ||
|
|
||
| !yarn.lock | ||
|
|
||
| # detox | ||
| artifacts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { MOBILE_KEY } from '@env'; | ||
|
|
||
| import { | ||
| AutoEnvAttributes, | ||
| LDProvider, | ||
| ReactNativeLDClient, | ||
| } from '@launchdarkly/react-native-client-sdk'; | ||
|
|
||
| import Welcome from './src/welcome'; | ||
|
|
||
| const featureClient = new ReactNativeLDClient(MOBILE_KEY, AutoEnvAttributes.Enabled, { | ||
| debug: true, | ||
| applicationInfo: { | ||
| id: 'ld-rn-fdv2-test-app', | ||
| version: '0.0.1', | ||
| }, | ||
| // @ts-ignore dataSystem is @internal | ||
| dataSystem: {}, | ||
| }); | ||
|
|
||
| const App = () => ( | ||
| <LDProvider client={featureClient}> | ||
| <Welcome /> | ||
| </LDProvider> | ||
| ); | ||
|
|
||
| export default App; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # LaunchDarkly React Native SDK - FDv2 Example App | ||
|
|
||
| This is a minimal example app that demonstrates the experimental FDv2 data system | ||
| for the React Native SDK. | ||
|
|
||
| > **Note:** FDv2 support is `@internal` and experimental. It is not ready for | ||
| > production use and may change or be removed without notice. | ||
|
|
||
| ## Features Demonstrated | ||
|
|
||
| - SDK initialization with the `dataSystem` option (FDv2 protocol) | ||
| - Connection mode switching for all FDv2 modes: | ||
| - **Streaming** - real-time flag updates with polling fallback | ||
| - **Polling** - periodic polling only | ||
| - **Offline** - cached flags only, no network | ||
| - **One-Shot** - initialize then stop (no persistent synchronizer) | ||
| - **Background** - low-frequency polling for background state | ||
| - **Automatic** - clear the override and use automatic mode selection | ||
| - Context identification | ||
| - Boolean flag evaluation | ||
|
|
||
| ## Quickstart | ||
|
|
||
| 1. At the js-core repo root, install dependencies and build: | ||
|
|
||
| ```shell | ||
| yarn && yarn build | ||
| ``` | ||
|
|
||
| 2. Create an `.env` file in this directory (`example-fdv2/`) with your mobile key: | ||
|
|
||
| ```shell | ||
| MOBILE_KEY=mob-your-mobile-key-here | ||
| ``` | ||
|
|
||
| 3. Update the flag key in `src/welcome.tsx` if needed (defaults to `sample-feature`). | ||
|
|
||
| 4. Run the app: | ||
|
|
||
| ```shell | ||
| # iOS | ||
| yarn ios | ||
|
|
||
| # Android | ||
| yarn android | ||
| ``` | ||
|
|
||
| > **Note:** You may need to run `npx expo prebuild` before the first iOS or | ||
| > Android build. | ||
|
|
||
| ## Caveats | ||
|
|
||
| - **Network-based automatic mode switching** is not yet implemented. The wiring | ||
| is in place, but `RNStateDetector` does not yet emit network state changes. | ||
| Lifecycle-based switching (foreground/background) works. | ||
| - The `dataSystem` option and `setConnectionMode()` are marked `@internal` and | ||
| require `@ts-ignore` to use from TypeScript. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "expo": { | ||
| "name": "react-native-example-fdv2", | ||
| "slug": "react-native-example-fdv2", | ||
| "version": "1.0.0", | ||
| "orientation": "portrait", | ||
| "userInterfaceStyle": "light", | ||
| "assetBundlePatterns": ["**/*"], | ||
| "ios": { | ||
| "supportsTablet": true, | ||
| "bundleIdentifier": "com.anonymous.reactnativeexamplefdv2" | ||
| }, | ||
| "android": { | ||
| "adaptiveIcon": { | ||
| "backgroundColor": "#ffffff" | ||
| }, | ||
| "package": "com.anonymous.reactnativeexamplefdv2" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| module.exports = function (api) { | ||
| api.cache(true); | ||
| return { | ||
| presets: ['babel-preset-expo'], | ||
| plugins: [ | ||
| [ | ||
| 'module:react-native-dotenv', | ||
| { | ||
| safe: true, | ||
| allowUndefined: false, | ||
| }, | ||
| ], | ||
| ], | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // We have to use a custom entrypoint for monorepo workspaces to work. | ||
| // https://docs.expo.dev/guides/monorepos/#change-default-entrypoint | ||
| import { registerRootComponent } from 'expo'; | ||
|
|
||
| import App from './App'; | ||
|
|
||
| // registerRootComponent calls AppRegistry.registerComponent('main', () => App); | ||
| // It also ensures that whether you load the app in Expo Go or in a native build, | ||
| // the environment is set up appropriately | ||
| registerRootComponent(App); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // We need to use a custom metro config for monorepo workspaces to work. | ||
| // https://docs.expo.dev/guides/monorepos/#modify-the-metro-config | ||
| /** | ||
| * @type {import('expo/metro-config')} | ||
| */ | ||
| const { getDefaultConfig } = require('expo/metro-config'); | ||
| const path = require('path'); | ||
|
|
||
| // Find the project and workspace directories | ||
| const projectRoot = __dirname; | ||
| // This can be replaced with `find-yarn-workspace-root` | ||
| const workspaceRoot = path.resolve(projectRoot, '../../../..'); | ||
|
|
||
| const config = getDefaultConfig(projectRoot); | ||
|
|
||
| // 1. Watch all files within the monorepo | ||
| config.watchFolders = [workspaceRoot]; | ||
| // 2. Let Metro know where to resolve packages and in what order | ||
| config.resolver.nodeModulesPaths = [ | ||
| path.resolve(projectRoot, 'node_modules'), | ||
| path.resolve(workspaceRoot, 'node_modules'), | ||
| ]; | ||
| // 3. Force Metro to resolve (sub)dependencies only from the `nodeModulesPaths` | ||
| config.resolver.disableHierarchicalLookup = true; | ||
|
|
||
| module.exports = config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| { | ||
| "name": "@launchdarkly/react-native-example-fdv2", | ||
| "private": true, | ||
| "version": "0.0.1", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "start": "expo start --reset-cache", | ||
| "android": "expo run:android", | ||
| "ios": "expo run:ios", | ||
| "web": "expo start --web --clear" | ||
| }, | ||
| "dependencies": { | ||
| "@launchdarkly/react-native-client-sdk": "10.15.2", | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
Outdated
|
||
| "@react-native-async-storage/async-storage": "^2.0.0", | ||
| "expo": "52.0.14", | ||
| "expo-status-bar": "~1.11.1", | ||
| "react": "18.3.1", | ||
| "react-native": "0.76.3", | ||
| "react-native-dotenv": "^3.4.9" | ||
| }, | ||
| "devDependencies": { | ||
| "@babel/core": "^7.20.0", | ||
| "@types/react": "~18.2.55", | ||
| "@types/react-native-dotenv": "^0.2.1", | ||
| "typescript": "^5.2.2" | ||
| }, | ||
| "packageManager": "yarn@3.4.1", | ||
| "installConfig": { | ||
| "hoistingLimits": "workspaces" | ||
| } | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
cursor[bot] marked this conversation as resolved.
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.