Skip to content
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

Fix regression that made the SDK unusable in React Native apps #52

Merged
merged 5 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .vscode/launch.json
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
}
]
}
42 changes: 21 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "configcat-react",
"version": "4.5.0",
"version": "4.6.0",
"scripts": {
"build": "npm run build:esm && npm run build:cjs",
"build:esm": "tsc -p tsconfig.build.esm.json && gulp esm",
Expand Down
55 changes: 20 additions & 35 deletions samples/next-js-sample/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion samples/next-js-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"configcat-react": "4.5.0",
"configcat-react": "^4.5.0",
"next": "14.1.4",
"react": "^18",
"react-dom": "^18"
Expand Down
35 changes: 35 additions & 0 deletions samples/react-native-sample/.gitignore
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
28 changes: 28 additions & 0 deletions samples/react-native-sample/App.tsx
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',
},
});
43 changes: 43 additions & 0 deletions samples/react-native-sample/ConfigCatHOC.tsx
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;
18 changes: 18 additions & 0 deletions samples/react-native-sample/ConfigCatHook.tsx
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;
30 changes: 30 additions & 0 deletions samples/react-native-sample/app.json
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.
Binary file added samples/react-native-sample/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.
Binary file added samples/react-native-sample/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/react-native-sample/assets/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions samples/react-native-sample/babel.config.js
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'],
};
};
Loading
Loading