Skip to content
This repository was archived by the owner on Jun 18, 2024. It is now read-only.

Commit 07d0b2c

Browse files
committed
feat: adjust signin to be able to fit notifications later on
- Signin flow is now not controlled by splash screen - Convert some files to ts and tsx files - Remove unused screen - change the isAuthenticatedUser state to authState which holds 3 different states, pending, signed_in and signed_out
1 parent 2402b13 commit 07d0b2c

21 files changed

+473
-721
lines changed

ios/Mitt Helsingborg.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@
654654
);
655655
inputPaths = (
656656
"${PODS_ROOT}/Target Support Files/Pods-MittHelsingborg-MittHelsingborgTests/Pods-MittHelsingborg-MittHelsingborgTests-frameworks.sh",
657-
"${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL/OpenSSL.framework/OpenSSL",
657+
"${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL-Universal/OpenSSL.framework/OpenSSL",
658658
);
659659
name = "[CP] Embed Pods Frameworks";
660660
outputPaths = (
@@ -744,7 +744,7 @@
744744
);
745745
inputPaths = (
746746
"${PODS_ROOT}/Target Support Files/Pods-MittHelsingborg/Pods-MittHelsingborg-frameworks.sh",
747-
"${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL/OpenSSL.framework/OpenSSL",
747+
"${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL-Universal/OpenSSL.framework/OpenSSL",
748748
);
749749
name = "[CP] Embed Pods Frameworks";
750750
outputPaths = (

ios/Mitt Helsingborg.xcworkspace/contents.xcworkspacedata

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ios/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ SPEC CHECKSUMS:
585585
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
586586
DoubleConversion: cf9b38bf0b2d048436d9a82ad2abe1404f11e7de
587587
FBLazyVector: 7b423f9e248eae65987838148c36eec1dbfe0b53
588-
FBReactNativeSpec: e684313f7bad785e52bef46967b2161b87fa64d7
588+
FBReactNativeSpec: 51246358c40fe0d0c678a8ed1ba40fbd60f8fae3
589589
Flipper: d3da1aa199aad94455ae725e9f3aa43f3ec17021
590590
Flipper-DoubleConversion: 38631e41ef4f9b12861c67d17cb5518d06badc41
591591
Flipper-Folly: 755929a4f851b2fb2c347d533a23f191b008554c
@@ -650,4 +650,4 @@ SPEC CHECKSUMS:
650650

651651
PODFILE CHECKSUM: 47660d4d544cbf2e0e1da1d1089da4066473d1e6
652652

653-
COCOAPODS: 1.10.1
653+
COCOAPODS: 1.11.2

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
"react-native-safe-area-context": "^3.1.9",
7474
"react-native-screens": "^2.16.1",
7575
"react-native-storybook-loader": "^2.0.4",
76-
"react-native-swiper": "^1.6.0",
7776
"react-native-tab-view": "^2.15.2",
7877
"react-native-vector-icons": "^7.1.0",
7978
"react-native-web": "^0.14.10",

source/navigator/AuthStack.js

-15
This file was deleted.

source/navigator/AuthStack.tsx

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React, { useEffect, useState } from "react";
2+
import { createStackNavigator } from "@react-navigation/stack";
3+
import Onboarding from "../screens/onboarding";
4+
import LoginScreen from "../screens/LoginScreen";
5+
6+
import StorageService, {
7+
ONBOARDING_DISABLED,
8+
} from "../services/StorageService";
9+
10+
const Stack = createStackNavigator();
11+
12+
const AuthStack = (): JSX.Element | null => {
13+
const [initialRouteName, setInitialRouteName] = useState<
14+
string | undefined
15+
>();
16+
17+
useEffect(() => {
18+
const trySetInitialRouteName = async () => {
19+
try {
20+
const isOnboardingDisabled = await StorageService.getData(
21+
ONBOARDING_DISABLED
22+
);
23+
setInitialRouteName(isOnboardingDisabled ? "Login" : "Onboarding");
24+
} catch (error) {
25+
setInitialRouteName("Onboarding");
26+
}
27+
};
28+
29+
void trySetInitialRouteName();
30+
}, []);
31+
32+
if (initialRouteName === undefined) return null;
33+
34+
return (
35+
<Stack.Navigator
36+
initialRouteName={initialRouteName}
37+
screenOptions={{ headerShown: false }}
38+
>
39+
<Stack.Screen name="Onboarding" component={Onboarding} />
40+
<Stack.Screen name="Login" component={LoginScreen} />
41+
</Stack.Navigator>
42+
);
43+
};
44+
45+
export default AuthStack;

source/navigator/CustomStackNavigator.tsx

+28-18
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
import React, { useContext } from 'react';
2-
import env from 'react-native-config';
3-
import styled from 'styled-components/native';
1+
import React, { useContext } from "react";
2+
import env from "react-native-config";
3+
import styled from "styled-components/native";
44
import {
55
NavigationHelpersContext,
66
useNavigationBuilder,
77
StackRouter,
88
DefaultRouterOptions,
9-
} from '@react-navigation/native';
10-
import { Modal } from 'react-native';
11-
import AuthContext from '../store/AuthContext';
12-
import Card from '../components/molecules/Card/Card';
13-
import Text from '../components/atoms/Text/Text';
14-
import useTouchActivity, { UseTouchParameters } from '../hooks/useTouchActivity';
9+
} from "@react-navigation/native";
10+
import { Modal } from "react-native";
11+
import AuthContext from "../store/AuthContext";
12+
import Card from "../components/molecules/Card/Card";
13+
import Text from "../components/atoms/Text/Text";
14+
import useTouchActivity, {
15+
UseTouchParameters,
16+
} from "../hooks/useTouchActivity";
17+
18+
import AUTH_STATE from "../store/types";
1519

1620
const FlexWrapper = styled.View`
1721
flex: 1;
@@ -59,18 +63,18 @@ const CustomStackNavigator = ({
5963
children,
6064
screenOptions,
6165
contentStyle,
62-
}: Props) => {
66+
}: Props): JSX.Element[] => {
6367
const { state, navigation, descriptors } = useNavigationBuilder(StackRouter, {
6468
children,
6569
screenOptions,
6670
initialRouteName,
6771
});
68-
const { handleLogout, isAuthenticated, handleRefreshSession } = useContext(AuthContext);
72+
const { handleLogout, authState, handleRefreshSession } =
73+
useContext(AuthContext);
6974

7075
const handleEndUserSession = async () => {
71-
if (isAuthenticated) {
76+
if (authState === AUTH_STATE.SIGNED_IN) {
7277
await handleLogout();
73-
navigation.navigate('Start');
7478
}
7579
};
7680

@@ -99,14 +103,17 @@ const CustomStackNavigator = ({
99103
};
100104

101105
const NavigatorContextComponent = (
102-
<NavigationHelpersContext.Provider key="navigationHelpersContext" value={navigation}>
106+
<NavigationHelpersContext.Provider
107+
key="navigationHelpersContext"
108+
value={navigation}
109+
>
103110
<FlexWrapper {...panResponder.panHandlers} style={[contentStyle]}>
104111
{descriptors[state.routes[state.index].key].render()}
105112
</FlexWrapper>
106113
</NavigationHelpersContext.Provider>
107114
);
108115

109-
const showInactivityModal = !isActive && isAuthenticated;
116+
const showInactivityModal = !isActive && authState === AUTH_STATE.SIGNED_IN;
110117

111118
const InactivityDialogComponent = (
112119
<Modal
@@ -123,13 +130,16 @@ const CustomStackNavigator = ({
123130
<Card.Body>
124131
<Card.Title>Är du fortfarande där?</Card.Title>
125132
<Card.Text>
126-
Du har varit inaktiv under en längre tid, för att fortsätta använda appen behöver
127-
du göra ett aktivt val.
133+
Du har varit inaktiv under en längre tid, för att fortsätta
134+
använda appen behöver du göra ett aktivt val.
128135
</Card.Text>
129136
<Card.Button colorSchema="red" onClick={handleEndUserSession}>
130137
<Text>Nej</Text>
131138
</Card.Button>
132-
<Card.Button colorSchema="green" onClick={handleContinueUserSession}>
139+
<Card.Button
140+
colorSchema="green"
141+
onClick={handleContinueUserSession}
142+
>
133143
<Text>Ja</Text>
134144
</Card.Button>
135145
</Card.Body>

source/navigator/RootNavigator.tsx

+28-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useContext } from "react";
22
import { createStackNavigator } from "@react-navigation/stack";
33
import { SplashScreen, FormCaseScreen, DevFeaturesScreen } from "../screens";
44
import AuthStack from "./AuthStack";
@@ -7,6 +7,9 @@ import BottomBarNavigator from "./BottomBarNavigator";
77

88
import FeatureModal from "../screens/featureModalScreens/FeatureModalNavigator";
99

10+
import AuthContext from "../store/AuthContext";
11+
import AUTH_STATE from "../store/types";
12+
1013
const MainStack = createStackNavigator();
1114
const RootStack = createStackNavigator();
1215

@@ -17,22 +20,29 @@ const forFade = ({ current }) => ({
1720
},
1821
});
1922

20-
const MainStackScreen = (): JSX.Element => (
21-
<CustomStackNavigator
22-
initialRouteName="Start"
23-
screenOptions={{ headerShown: false }}
24-
>
25-
<>
26-
<MainStack.Screen name="Start" component={SplashScreen} />
27-
<MainStack.Screen
28-
name="Auth"
29-
component={AuthStack}
30-
options={{ cardStyleInterpolator: forFade }}
31-
/>
23+
const MainStackScreen = (): JSX.Element => {
24+
const { authState } = useContext(AuthContext);
25+
26+
if (authState === AUTH_STATE.PENDING) {
27+
return <SplashScreen />;
28+
}
29+
30+
if (authState === AUTH_STATE.SIGNED_OUT) {
31+
return <AuthStack />;
32+
}
33+
34+
return (
35+
<CustomStackNavigator
36+
initialRouteName="App"
37+
screenOptions={{ headerShown: false }}
38+
>
3239
<MainStack.Screen
3340
name="App"
3441
component={BottomBarNavigator}
35-
options={{ cardStyleInterpolator: forFade, gestureEnabled: false }}
42+
options={{
43+
cardStyleInterpolator: forFade,
44+
gestureEnabled: false,
45+
}}
3646
/>
3747
<MainStack.Screen
3848
name="Form"
@@ -48,12 +58,13 @@ const MainStackScreen = (): JSX.Element => (
4858
gestureEnabled: false,
4959
}}
5060
/>
51-
</>
52-
</CustomStackNavigator>
53-
);
61+
</CustomStackNavigator>
62+
);
63+
};
5464

5565
const RootStackScreen = (): JSX.Element => (
5666
<RootStack.Navigator
67+
initialRouteName="Main"
5768
mode="modal"
5869
screenOptions={{
5970
cardStyle: { backgroundColor: "transparent" },

source/screens/DevFeaturesScreen.js renamed to source/screens/DevFeaturesScreen.tsx

+16-18
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import FormList from 'app/components/organisms/FormList/FormList';
2-
import AuthContext from 'app/store/AuthContext';
3-
import { CaseDispatch } from 'app/store/CaseContext';
4-
import PropTypes from 'prop-types';
5-
import React, { useContext } from 'react';
6-
import styled from 'styled-components/native';
7-
import env from 'react-native-config';
8-
import { Button, Text } from '../components/atoms';
9-
import Header from '../components/molecules/Header';
10-
import ScreenWrapper from '../components/molecules/ScreenWrapper';
11-
import StorageService from '../services/StorageService';
1+
import PropTypes from "prop-types";
2+
import React, { useContext } from "react";
3+
import styled from "styled-components/native";
4+
import env from "react-native-config";
5+
import { CaseDispatch } from "../store/CaseContext";
6+
import AuthContext from "../store/AuthContext";
7+
import FormList from "../components/organisms/FormList/FormList";
8+
import { Button, Text } from "../components/atoms";
9+
import Header from "../components/molecules/Header";
10+
import ScreenWrapper from "../components/molecules/ScreenWrapper";
11+
import StorageService from "../services/StorageService";
1212

1313
const Container = styled.ScrollView`
1414
flex: 1;
@@ -21,12 +21,11 @@ const FieldWrapper = styled.View`
2121
margin-bottom: 8px;
2222
`;
2323

24-
const DeveloperScreen = (props) => {
25-
const { navigation } = props;
24+
const DeveloperScreen = ({ navigation }: any) => {
2625
const { createCase } = useContext(CaseDispatch);
2726
const authContext = useContext(AuthContext);
2827

29-
const colorSchema = 'neutral';
28+
const colorSchema = "neutral";
3029

3130
return (
3231
<ScreenWrapper>
@@ -39,7 +38,7 @@ const DeveloperScreen = (props) => {
3938
createCase(
4039
form,
4140
async (newCase) => {
42-
navigation.navigate('Form', { caseData: newCase });
41+
navigation.navigate("Form", { caseData: newCase });
4342
},
4443
true
4544
);
@@ -52,9 +51,8 @@ const DeveloperScreen = (props) => {
5251
variant="outlined"
5352
colorSchema={colorSchema}
5453
onClick={async () => {
55-
StorageService.clearData();
54+
void StorageService.clearData();
5655
await authContext.handleLogout();
57-
navigation.navigate('Start');
5856
}}
5957
>
6058
<Text>Nollställ appdata</Text>
@@ -67,7 +65,7 @@ const DeveloperScreen = (props) => {
6765
variant="contained"
6866
colorSchema={colorSchema}
6967
onClick={async () => {
70-
navigation.navigate('App');
68+
navigation.navigate("App");
7169
}}
7270
>
7371
<Text>Tillbaka</Text>

0 commit comments

Comments
 (0)