-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix regression that made the SDK unusable in React Native apps (#52)
* Fix regression that made the SDK unusable in React Native apps * Add React Native sample app * npm audit fix * Bump version
- Loading branch information
Showing
21 changed files
with
13,522 additions
and
75 deletions.
There are no files selected for viewing
This file contains 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,18 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Debug Tests", | ||
"type": "node", | ||
"request": "launch", | ||
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts", | ||
"args": ["test", "--runInBand", "--no-cache", "--watchAll=false"], | ||
"cwd": "${workspaceRoot}", | ||
"protocol": "inspector", | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen", | ||
"env": { "CI": "true" }, | ||
"disableOptimisticBPs": true | ||
} | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,35 @@ | ||
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files | ||
|
||
# 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 |
This file contains 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,28 @@ | ||
import { ConfigCatProvider, LogLevel, createConsoleLogger, withConfigCatClient } from 'configcat-react'; | ||
import { StatusBar } from 'expo-status-bar'; | ||
import { StyleSheet, Text, View } from 'react-native'; | ||
import ButtonClassComponent from './ConfigCatHOC'; | ||
import ButtonFunctionComponent from './ConfigCatHook'; | ||
|
||
const ConfigCatButtonClassComponent = withConfigCatClient(ButtonClassComponent); | ||
|
||
export default function App() { | ||
return ( | ||
<ConfigCatProvider sdkKey="zVPVCO5_LS9VnDcpIDE84g/zVPVCBScEzDn-VNq0dnYog" options={{logger: createConsoleLogger(LogLevel.Info)}}> | ||
<View style={styles.container}> | ||
<ConfigCatButtonClassComponent text={"Feature Enabled (with HOC)"} /> | ||
<ButtonFunctionComponent text={"Feature Enabled (with HOOKS)"} /> | ||
<StatusBar style="auto" /> | ||
</View> | ||
</ConfigCatProvider> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: '#fff', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
}); |
This file contains 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,43 @@ | ||
import React from "react"; | ||
import { WithConfigCatClientProps } from "configcat-react"; | ||
import { Button, Text, View } from "react-native"; | ||
|
||
class ButtonClassComponent extends React.Component< | ||
{ text: string } & WithConfigCatClientProps, | ||
{ isEnabled: boolean, loading: boolean } | ||
> { | ||
constructor(props: { text: string } & WithConfigCatClientProps) { | ||
super(props); | ||
|
||
this.state = { isEnabled: false, loading: true }; | ||
} | ||
|
||
componentDidUpdate(prevProps: any) { | ||
// To achieve hot reload on config.json updates. | ||
if (prevProps?.lastUpdated !== this.props.lastUpdated) { | ||
this.evaluateFeatureFlag(); | ||
} | ||
} | ||
|
||
componentDidMount() { | ||
this.evaluateFeatureFlag(); | ||
} | ||
|
||
evaluateFeatureFlag() { | ||
this.props | ||
.getValue("isAwesomeFeatureEnabled", false) | ||
.then((v: boolean) => this.setState({ isEnabled: v, loading: false })); | ||
} | ||
|
||
render() { | ||
return this.state.loading | ||
? (<View style={{marginTop: 10, marginBottom: 10}}><Text>Loading...</Text></View>) | ||
: ( | ||
<View style={{marginTop: 10, marginBottom: 10}}> | ||
<Button disabled={!this.state.isEnabled} onPress={() => alert("ConfigCat <3 React")} title={this.props.text} /> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
export default ButtonClassComponent; |
This file contains 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,18 @@ | ||
import React from "react"; | ||
import { useFeatureFlag } from "configcat-react"; | ||
import { Button, Text, View } from "react-native"; | ||
|
||
const ButtonFunctionComponent: React.FunctionComponent<{ text: string }> = ({ | ||
text, | ||
}) => { | ||
const { value: isEnabled, loading } = useFeatureFlag("isAwesomeFeatureEnabled", false); | ||
return loading | ||
? (<View style={{marginTop: 10, marginBottom: 10}}><Text>Loading...</Text></View>) | ||
: ( | ||
<View style={{marginTop: 10, marginBottom: 10}}> | ||
<Button disabled={!isEnabled} onPress={() => alert("ConfigCat <3 React")} title={text} /> | ||
</View> | ||
); | ||
}; | ||
|
||
export default ButtonFunctionComponent; |
This file contains 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,30 @@ | ||
{ | ||
"expo": { | ||
"name": "react-native-sample", | ||
"slug": "react-native-sample", | ||
"version": "1.0.0", | ||
"orientation": "portrait", | ||
"icon": "./assets/icon.png", | ||
"userInterfaceStyle": "light", | ||
"splash": { | ||
"image": "./assets/splash.png", | ||
"resizeMode": "contain", | ||
"backgroundColor": "#ffffff" | ||
}, | ||
"assetBundlePatterns": [ | ||
"**/*" | ||
], | ||
"ios": { | ||
"supportsTablet": true | ||
}, | ||
"android": { | ||
"adaptiveIcon": { | ||
"foregroundImage": "./assets/adaptive-icon.png", | ||
"backgroundColor": "#ffffff" | ||
} | ||
}, | ||
"web": { | ||
"favicon": "./assets/favicon.png" | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,6 @@ | ||
module.exports = function(api) { | ||
api.cache(true); | ||
return { | ||
presets: ['babel-preset-expo'], | ||
}; | ||
}; |
Oops, something went wrong.