Skip to content

Commit e198e04

Browse files
committed
Checkbox display modal on click
1 parent ea00f72 commit e198e04

3 files changed

Lines changed: 36 additions & 34 deletions

File tree

src/App.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
22
import { NavigationContainer } from '@react-navigation/native';
33
import { createNativeStackNavigator } from '@react-navigation/native-stack';
4+
<<<<<<< HEAD:src/App.tsx
45
import { registerRootComponent } from 'expo';
6+
=======
7+
>>>>>>> 20555f6 (Checkbox display modal on click):App.tsx
58
import React, { useContext } from 'react';
69
import { View } from 'react-native';
710
import { Provider } from 'react-redux';
@@ -48,12 +51,11 @@ function CustomTabBar({ navigation }) {
4851
}
4952

5053
function TabNavigator() {
51-
const { state, signout } = useContext(AuthContext);
5254
return (
5355
<Tab.Navigator
5456
screenOptions={{ headerShown: false }}
5557
tabBar={(props) => <CustomTabBar {...props} />}>
56-
<Tab.Screen name="CaseContactListScreen" component={CaseContactListScreen} initialParams={{staySignedIn: state.staySignedIn}} />
58+
<Tab.Screen name="CaseContactListScreen" component={CaseContactListScreen} />
5759
<Tab.Screen name="AccountScreen" component={AccountScreen} />
5860
<Tab.Screen name="CaseContactCreateScreen" component={CaseContactCreateScreen} />
5961
<Tab.Screen name="CaseContactDetailScreen" component={CaseContactDetailScreen} />
@@ -69,7 +71,7 @@ function MainApp() {
6971
tryLocalSignin();
7072
}, []);
7173
*/
72-
74+
7375
return (
7476
<NavigationContainer>
7577
<RootStack.Navigator>

src/components/AuthForm.tsx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState, useContext } from 'react';
2-
import { TextInput, Text, StyleSheet} from 'react-native';
2+
import { TextInput, Text, StyleSheet, Modal, Alert, Pressable, View} from 'react-native';
33
import { Context as AuthContext } from 'src/components/context/AuthContext';
44
import tw from 'twrnc';
55

@@ -9,7 +9,7 @@ import CheckBox from './CheckBox';
99
interface LoginFieldProps {
1010
errorMessage: string;
1111
submitButtonText: string;
12-
onSubmit: ({ email, password, staySignedin}) => void;
12+
onSubmit: ({ email, password}) => void;
1313
style?: StyleSheet.NamedStyles<any>;
1414
}
1515

@@ -22,6 +22,7 @@ const AuthForm: React.FC<LoginFieldProps> = ({
2222
const [email, setEmail] = useState<string>('');
2323
const [password, setPassword] = useState<string>('');
2424
const [staySignedIn, setStaySignedIn] = useState<boolean>(false)
25+
const [modalVisible, setModalVisible] = useState(false);
2526

2627
const { signin } = useContext(AuthContext);
2728

@@ -33,6 +34,14 @@ const AuthForm: React.FC<LoginFieldProps> = ({
3334
}
3435
};
3536

37+
const handleStaySignInToggle = () => {
38+
if (staySignedIn) {
39+
setStaySignedIn(false)
40+
}else {
41+
setStaySignedIn(true)
42+
setModalVisible(true)
43+
}
44+
}
3645
return (
3746
<>
3847
<TextInput
@@ -53,7 +62,7 @@ const AuthForm: React.FC<LoginFieldProps> = ({
5362
onChangeText={setPassword}
5463
/>
5564
<CheckBox
56-
onPress={() => setStaySignedIn(!staySignedIn)}
65+
onPress={handleStaySignInToggle}
5766
title="Stay Logged In"
5867
isChecked={staySignedIn}
5968
/>
@@ -64,6 +73,24 @@ const AuthForm: React.FC<LoginFieldProps> = ({
6473
title="Sign In"
6574
onPress={handleSignIn}
6675
/>
76+
<Modal
77+
animationType="slide"
78+
transparent={true}
79+
visible={modalVisible}
80+
onRequestClose={() => {
81+
setModalVisible(!modalVisible);
82+
}}>
83+
<View style={tw`flex-1 justify-center items-center`}>
84+
<View style={tw`m-5 bg-white rounded-2xl p-9 items-center shadow-lg`}>
85+
<Text style={tw`mb-4 text-center`}>Your session will stay active until you sign out.</Text>
86+
<Pressable
87+
style={tw`rounded-2xl px-4 py-2 bg-[#345073]`}
88+
onPress={() => setModalVisible(!modalVisible)}>
89+
<Text style={tw`text-white font-bold text-center`}>OK</Text>
90+
</Pressable>
91+
</View>
92+
</View>
93+
</Modal>
6794
</>
6895
);
6996
};

src/screens/CaseContactListScreen.tsx

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
import { View, Text, FlatList, SafeAreaView, Modal, Alert, Pressable, StyleSheet } from 'react-native';
1+
import { View, Text, FlatList} from 'react-native';
22
import tw from 'twrnc';
3-
import { useState, useEffect } from 'react'
43
import React from 'react';
54

65
import CaseContactListCard from '../components/CaseContactListCard';
76

87
const CaseContactListScreen = ({ navigation, route }) => {
9-
const [modalVisible, setModalVisible] = useState(true);
108
const data = [{ name: '🦋CINA-11-1002' }, { name: '🦋CINA-11-1003' }, { name: '🦋CINA-11-1004' }];
119

12-
useEffect(() => {
13-
if (route.params.staySignedIn) {
14-
setModalVisible(true)
15-
}
16-
}, []);
17-
1810
return (
1911
<>
2012
<View style={tw`flex items-center gap-3 flex-1 bg-[#d5d7da]`}>
@@ -38,25 +30,6 @@ const CaseContactListScreen = ({ navigation, route }) => {
3830
</View>
3931
</View>
4032
</View>
41-
<Modal
42-
animationType="slide"
43-
transparent={true}
44-
visible={modalVisible}
45-
onRequestClose={() => {
46-
Alert.alert('Modal has been closed.');
47-
setModalVisible(!modalVisible);
48-
}}>
49-
<View style={tw`flex-1 justify-center items-center`}>
50-
<View style={tw`m-5 bg-white rounded-2xl p-9 items-center shadow-lg`}>
51-
<Text style={tw`mb-4 text-center`}>Your session will stay active until you sign out.</Text>
52-
<Pressable
53-
style={tw`rounded-2xl px-4 py-2 bg-[#345073]`}
54-
onPress={() => setModalVisible(!modalVisible)}>
55-
<Text style={tw`text-white font-bold text-center`}>OK</Text>
56-
</Pressable>
57-
</View>
58-
</View>
59-
</Modal>
6033
</>
6134
);
6235
};

0 commit comments

Comments
 (0)