Skip to content

Commit a967d12

Browse files
committed
install redux
1 parent 7794fdb commit a967d12

File tree

19 files changed

+234
-64
lines changed

19 files changed

+234
-64
lines changed

template/App.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import useNetworkError from 'hooks/useNetworkError';
1212
import useStartupTime from 'hooks/useStartupTime';
1313
// import useNotifications from 'hooks/useNotifications';
1414
import useAppState from 'react-native-appstate-hook';
15+
import { Provider } from 'react-redux';
16+
import store from './src/store';
1517

1618
enableScreens();
1719

@@ -43,7 +45,11 @@ const App = () => {
4345
onBackground: () => console.warn('App went to background'),
4446
});
4547

46-
return <Router />;
48+
return (
49+
<Provider store={store}>
50+
<Router />
51+
</Provider>
52+
);
4753
};
4854

4955
let codePushOptions: CodePushOptions = {

template/__tests__/App-test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import App from '../App';
1010
import renderer from 'react-test-renderer';
1111
jest.useFakeTimers();
1212

13+
// eslint-disable-next-line jest/expect-expect
1314
it('renders correctly', async () => {
1415
renderer.create(<App />);
1516
});

template/babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports = {
2626
'screens': './src/screens',
2727
'@utils': './src/utils',
2828
'@auth': './src/modules/auth',
29+
'@store': './src/store',
2930
},
3031
},
3132
],

template/ios/Podfile.lock

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ PODS:
285285
- React-jsi (= 0.64.1)
286286
- React-perflogger (= 0.64.1)
287287
- React-jsinspector (0.64.1)
288+
- react-native-flipper (0.90.2):
289+
- React-Core
288290
- react-native-netinfo (6.0.0):
289291
- React-Core
290292
- react-native-safe-area-context (3.2.0):
@@ -463,6 +465,7 @@ DEPENDENCIES:
463465
- React-jsi (from `../node_modules/react-native/ReactCommon/jsi`)
464466
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
465467
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
468+
- react-native-flipper (from `../node_modules/react-native-flipper`)
466469
- "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)"
467470
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
468471
- react-native-startup-time (from `../node_modules/react-native-startup-time`)
@@ -550,6 +553,8 @@ EXTERNAL SOURCES:
550553
:path: "../node_modules/react-native/ReactCommon/jsiexecutor"
551554
React-jsinspector:
552555
:path: "../node_modules/react-native/ReactCommon/jsinspector"
556+
react-native-flipper:
557+
:path: "../node_modules/react-native-flipper"
553558
react-native-netinfo:
554559
:path: "../node_modules/@react-native-community/netinfo"
555560
react-native-safe-area-context:
@@ -640,6 +645,7 @@ SPEC CHECKSUMS:
640645
React-jsi: 5de8204706bd872b78ea646aee5d2561ca1214b6
641646
React-jsiexecutor: 124e8f99992490d0d13e0649d950d3e1aae06fe9
642647
React-jsinspector: 500a59626037be5b3b3d89c5151bc3baa9abf1a9
648+
react-native-flipper: 452e2fcd89eed2333ecc2a1b543b12684d33c033
643649
react-native-netinfo: e849fc21ca2f4128a5726c801a82fc6f4a6db50d
644650
react-native-safe-area-context: f0906bf8bc9835ac9a9d3f97e8bde2a997d8da79
645651
react-native-startup-time: 740451fcbc7e3c8f67b036365387401ab917de1c
@@ -674,6 +680,6 @@ SPEC CHECKSUMS:
674680
Yoga: a7de31c64fe738607e7a3803e3f591a4b1df7393
675681
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
676682

677-
PODFILE CHECKSUM: 02723fb052b0e4d0651d4a9dfee095ed6ea75f79
683+
PODFILE CHECKSUM: 4674ef6157284fb2142350582ee9f2824559eb59
678684

679685
COCOAPODS: 1.10.1

template/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@react-native-community/netinfo": "^6.0.0",
2020
"@react-navigation/native": "^5.9.3",
2121
"@react-navigation/stack": "^5.14.3",
22+
"@reduxjs/toolkit": "^1.5.1",
2223
"@sentry/react-native": "^2.2.2",
2324
"code-push": "4.0.2",
2425
"i18next": "^20.2.2",
@@ -30,6 +31,7 @@
3031
"react-native-dotenv": "^2.5.0",
3132
"react-native-fast-image": "^8.3.4",
3233
"react-native-file-logger": "^0.2.1",
34+
"react-native-flipper": "^0.90.2",
3335
"react-native-gesture-handler": "^1.10.3",
3436
"react-native-keychain": "^6.2.0",
3537
"react-native-permissions": "^3.0.1",
@@ -42,6 +44,8 @@
4244
"react-native-vector-icons": "^8.1.0",
4345
"react-native-webview": "^11.0.2",
4446
"react-query": "^3.12.0",
47+
"react-redux": "^7.2.4",
48+
"redux-flipper": "^1.4.2",
4549
"styled-components": "^5.2.1",
4650
"styled-system": "^5.1.5"
4751
},

template/src/components/Counter.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import { useTranslation } from 'react-i18next';
77
const MemoizedComponent = React.memo(() => <View />);
88
const RerenderedComponent = () => <View />;
99

10-
MemoizedComponent.whyDidYouRender = true;
11-
RerenderedComponent.whyDidYouRender = true;
12-
1310
const Counter = () => {
1411
const [counter, setCounter] = useState<number>(0);
1512
const { t } = useTranslation();

template/src/components/CustomText.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { space, SpaceProps, layout, LayoutProps, compose, typography, Typography
55

66
interface StyleProps extends SpaceProps, TypographyProps, LayoutProps, TextProps {
77
flex?: number | string;
8-
color?: string;
8+
99
capitalize?: boolean;
1010
underline?: boolean;
1111
debug?: boolean;
@@ -23,7 +23,7 @@ const Container = styled(Text)<StyleProps>`
2323
: css``};
2424
text-align-vertical: center;
2525
text-decoration-line: ${({ underline }) => (underline ? 'underline' : 'none')};
26-
color: ${({ color }) => color};
26+
color: ${({ theme }) => theme.colors.main};
2727
${({ capitalize }) =>
2828
capitalize
2929
? css`
@@ -42,11 +42,7 @@ Container.defaultProps = {
4242
};
4343

4444
const CustomText = ({ children, color, ...props }: PropsWithChildren<StyleProps>) => {
45-
return (
46-
<Container color={color ?? '#000'} {...props}>
47-
{children}
48-
</Container>
49-
);
45+
return <Container {...props}>{children}</Container>;
5046
};
5147

5248
export default CustomText;

template/src/modules/auth/screens/Onboarding.tsx

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import useKeychainBiometrics from '../hooks/useKeychainBiometrics';
66
import useKeychainCredentials from '../hooks/useKeychainCredentials';
77
// import useStore from '../store';
88
import { useNavigation } from '@react-navigation/core';
9+
import { useDispatch, useSelector } from 'react-redux';
10+
import { authState } from '@store/slices';
11+
import { setToken } from '@store/slices/auth';
12+
import { log } from '@utils/console';
13+
// import { log } from 'src/utils/console';
914

1015
const Onboaring = () => {
1116
const { t } = useTranslation('onboarding');
@@ -14,24 +19,32 @@ const Onboaring = () => {
1419

1520
const { userCredentials } = useKeychainCredentials();
1621

17-
// const setToken = useStore((state) => state.setToken);
18-
22+
const { token } = useSelector(authState);
23+
const dispatch = useDispatch();
1924
useEffect(() => {
2025
if (userCredentials) {
2126
// Authentificate .then setToken
22-
// setToken('blabla');
27+
dispatch(
28+
setToken({
29+
token: '',
30+
}),
31+
);
2332
}
24-
}, [userCredentials]);
25-
33+
}, [dispatch, userCredentials]);
34+
log(token);
2635
return (
2736
<CustomScreen justifyContent={'space-evenly'} testID={'OnboardingScreen'}>
2837
<CustomText
2938
fontWeight={'700'}
3039
testID={'btnSign'}
3140
onPress={() => {
3241
// Authentificate .then setToken .then setStoreCredentials
33-
// setToken('blabla');
34-
setStoreCredentials(true);
42+
dispatch(
43+
setToken({
44+
token: 'dada',
45+
}),
46+
);
47+
// setStoreCredentials(true);
3548
}}>
3649
{t('sign')}
3750
</CustomText>
@@ -41,13 +54,14 @@ const Onboaring = () => {
4154
onPress={() => {
4255
// Send reset email and then deeplink to ResetPassword
4356
navigate('ResetPassword');
57+
setToken({
58+
token: '',
59+
});
4460
}}>
4561
{t('forgot')}
4662
</CustomText>
4763
</CustomScreen>
4864
);
4965
};
5066

51-
Onboaring.whyDidYouRender = true;
52-
5367
export default Onboaring;

template/src/modules/auth/store/index.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

template/src/navigation/Router.tsx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import React from 'react';
22
import { LinkingOptions, NavigationContainer } from '@react-navigation/native';
33
import { createStackNavigator } from '@react-navigation/stack';
4+
45
import { SafeAreaProvider } from 'react-native-safe-area-context';
56
import { navigationRef } from 'navigation/RootNavigation';
67
import { WHITE } from '@utils/colors';
78
import { authScreens, AuthStackParamList } from '@auth/screens';
89
import { commonScreens, CommonStackParamList, userScreens, UserStackParamList } from 'screens';
9-
// import useStore from '@auth/store';
10+
import { ThemeProvider } from 'styled-components';
11+
import { myTheme } from '../../theme';
12+
import { useSelector } from 'react-redux';
13+
import { authState } from '../store/slices';
1014

1115
const screenOptions = {
1216
cardStyle: { backgroundColor: WHITE },
@@ -17,29 +21,30 @@ type ParamList = CommonStackParamList & UserStackParamList & AuthStackParamList;
1721
export const Stack = createStackNavigator<ParamList>();
1822

1923
const linking: LinkingOptions = {
20-
prefixes: ['helloworld://'],
24+
prefixes: ['template://'],
2125
config: {
2226
screens: {},
2327
},
2428
};
2529

2630
export default function Router() {
27-
// const isLoggedIn = useStore((state) => !!state.token);
28-
const isLoggedIn = true;
31+
const { token } = useSelector(authState);
2932

3033
return (
3134
<NavigationContainer linking={linking} ref={navigationRef}>
3235
<SafeAreaProvider>
33-
<Stack.Navigator screenOptions={screenOptions}>
34-
{Object.entries({
35-
// Use some screens conditionally based on some condition
36-
...(isLoggedIn ? userScreens : authScreens),
37-
// Use the screens normally
38-
...commonScreens,
39-
}).map(([name, props]) => {
40-
return <Stack.Screen key={name} name={name as keyof ParamList} {...props} />;
41-
})}
42-
</Stack.Navigator>
36+
<ThemeProvider theme={myTheme}>
37+
<Stack.Navigator screenOptions={screenOptions}>
38+
{Object.entries({
39+
// Use some screens conditionally based on some condition
40+
...(token ? userScreens : authScreens),
41+
// Use the screens normally
42+
...commonScreens,
43+
}).map(([name, props]) => {
44+
return <Stack.Screen key={name} name={name as keyof ParamList} {...props} />;
45+
})}
46+
</Stack.Navigator>
47+
</ThemeProvider>
4348
</SafeAreaProvider>
4449
</NavigationContainer>
4550
);

0 commit comments

Comments
 (0)