Skip to content

Commit

Permalink
refactor: 스크린 범위 컴포넌트화
Browse files Browse the repository at this point in the history
  • Loading branch information
hobak12 committed Jan 12, 2023
1 parent cca0985 commit e45a0a5
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 86 deletions.
23 changes: 23 additions & 0 deletions src/components/PageContainer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { StyleSheet, SafeAreaView } from 'react-native';

const PageContainer = ({ children }) => {
return <SafeAreaView style={styles.screenArea}>{children}</SafeAreaView>;
};

const styles = StyleSheet.create({
screenArea: {
...Platform.select({
ios: {
flex: 1,
backgroundColor: 'white',
},
android: {
flex: 1,
paddingTop: 30,
backgroundColor: 'white',
},
}),
},
});

export default PageContainer;
2 changes: 2 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import TextButton from './TextButton';
import ToggleList from './ToggleList';
import CustomButton from './CustomButton';
import CustomInput from './CustomInput';
import PageContainer from './PageContainer';

export {
ManageList,
Expand All @@ -12,4 +13,5 @@ export {
GraphicStatus,
CustomButton,
CustomInput,
PageContainer,
};
19 changes: 3 additions & 16 deletions src/screen/LoginPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ToggleModeButton } from '../context/Theme';
import { useSignIn } from '../Hooks/useAuth';
import CustomButton from '../components/CustomButton';
import CustomInput from '../components/CustomInput';
import { PageContainer } from '../components/index';

const LoginPage = ({ navigation: { navigate } }) => {
const { theme } = useContext(ThemeContext);
Expand Down Expand Up @@ -52,7 +53,7 @@ const LoginPage = ({ navigation: { navigate } }) => {
};

return (
<SafeAreaView style={styles.screenArea}>
<PageContainer>
<LoginContainer theme={theme}>
<ToggleModeButton />
{/* 이메일 인풋 */}
Expand Down Expand Up @@ -97,7 +98,7 @@ const LoginPage = ({ navigation: { navigate } }) => {
buttonText="회원가입"
/>
</LoginContainer>
</SafeAreaView>
</PageContainer>
);
};

Expand All @@ -112,17 +113,3 @@ const LoginErrorText = styled.Text`
color: ${COLORS.DANGER};
padding: 10px 0;
`;

const styles = StyleSheet.create({
screenArea: {
...Platform.select({
ios: {
flex: 1,
},
android: {
flex: 1,
paddingTop: 20,
},
}),
},
});
31 changes: 8 additions & 23 deletions src/screen/MainPage.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { GraphicStatus } from '../components/index';
import { Text, FlatList, SafeAreaView, StyleSheet } from 'react-native';
import { Text, FlatList } from 'react-native';
import { useUID } from '../Hooks/useAuth';
import { useGetPillData } from '../Hooks/usePill';
import { ToggleList } from '../components';
import { useEffect, useState } from 'react';
import { PageContainer } from '../components/index';

const MainPage = () => {
const { data: uid } = useUID();
Expand All @@ -23,23 +24,23 @@ const MainPage = () => {

if (isError) {
return (
<SafeAreaView style={styles.screenArea}>
<PageContainer>
<Text>에러 페이지</Text>
<Text>{error.message}</Text>
</SafeAreaView>
</PageContainer>
);
}

if (isLoading || !initialLoad) {
return (
<SafeAreaView style={styles.screenArea}>
<PageContainer>
<Text>로딩 화면</Text>
</SafeAreaView>
</PageContainer>
);
}

return (
<SafeAreaView style={styles.screenArea}>
<PageContainer>
<FlatList
data={pillList}
keyExtractor={(item) => item.id}
Expand All @@ -54,24 +55,8 @@ const MainPage = () => {
/>
)}
/>
</SafeAreaView>
</PageContainer>
);
};

export default MainPage;

const styles = StyleSheet.create({
screenArea: {
...Platform.select({
ios: {
flex: 1,
backgroundColor: 'white',
},
android: {
flex: 1,
paddingTop: 30,
backgroundColor: 'white',
},
}),
},
});
29 changes: 7 additions & 22 deletions src/screen/MyPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Text, View, FlatList, StyleSheet, SafeAreaView } from 'react-native';
import { ManageList, CustomButton } from '../components';
import { useUID } from '../Hooks/useAuth';
import { useGetPillData } from '../Hooks/usePill';
import { PageContainer } from '../components/index';

const MyPage = ({ navigation: { navigate } }) => {
const { data: uid } = useUID();
Expand All @@ -11,30 +12,30 @@ const MyPage = ({ navigation: { navigate } }) => {
// 에러 핸들링: 통신 실패의 경우 보여주는 화면입니다.
if (isError) {
return (
<SafeAreaView style={styles.screenArea}>
<PageContainer>
<PageTitle>나의 약관리</PageTitle>
<View>
<Text>에러</Text>
<Text>{error.message}</Text>
</View>
</SafeAreaView>
</PageContainer>
);
}

// 통신 중
if (isLoading) {
return (
<SafeAreaView style={styles.screenArea}>
<PageContainer>
<PageTitle>나의 약관리</PageTitle>
<View>
<Text>Loading...</Text>
</View>
</SafeAreaView>
</PageContainer>
);
}

return (
<SafeAreaView style={styles.screenArea}>
<PageContainer>
<FlatList
data={pillList}
ListHeaderComponent={<PageTitle>나의 약관리</PageTitle>}
Expand Down Expand Up @@ -66,7 +67,7 @@ const MyPage = ({ navigation: { navigate } }) => {
</CustomButtonContainer>
}
/>
</SafeAreaView>
</PageContainer>
);
};

Expand All @@ -83,20 +84,4 @@ const CustomButtonContainer = styled.View`
margin: -8px 8px 0px;
`;

const styles = StyleSheet.create({
screenArea: {
...Platform.select({
ios: {
flex: 1,
backgroundColor: 'white',
},
android: {
flex: 1,
paddingTop: 20,
backgroundColor: 'white',
},
}),
},
});

export default MyPage;
16 changes: 3 additions & 13 deletions src/screen/SettingPage.jsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
import { CustomButton } from '../components';
import { View, SafeAreaView, StyleSheet } from 'react-native';
import { PageContainer } from '../components/index';

const SettingPage = ({ navigation: { navigate } }) => {
return (
<SafeAreaView style={styles.screenArea}>
<PageContainer>
<CustomButton
buttonText="로그아웃"
onPress={() => navigate('Stacks', { screen: '로그인' })}
/>
<CustomButton buttonText="다크 모드" />
</SafeAreaView>
</PageContainer>
);
};

export default SettingPage;

const styles = StyleSheet.create({
screenArea: {
...Platform.select({
android: {
paddingTop: 30,
},
}),
},
});
18 changes: 6 additions & 12 deletions src/screen/SignupPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FontAwesome } from '@expo/vector-icons';
import { COLORS } from '../shared/color';
import { ThemeContext } from '../context/Theme';
import { ToggleModeButton } from '../context/Theme';
import { PageContainer } from '../components/index';

const regex = {
email: new RegExp(/[a-z0-9]+@[a-z]+\.[a-z]{2,3}/),
Expand Down Expand Up @@ -61,7 +62,7 @@ const SignupPage = ({ navigation: { navigate } }) => {
};

return (
<SafeAreaView style={styles.screenArea}>
<PageContainer>
<FormContainer theme={theme}>
<BackToLoginPageButton onPress={() => navigate('로그인')}>
<FontAwesome
Expand All @@ -80,7 +81,7 @@ const SignupPage = ({ navigation: { navigate } }) => {
value={email}
onChangeText={setEmail}
onChange={(text) => validEmail(text)}
style={styles.textInputShadow}
style={styles1.textInputShadow}
/>

{correctEmail || (
Expand All @@ -102,7 +103,7 @@ const SignupPage = ({ navigation: { navigate } }) => {
onChangeText={setPassword}
onChange={(text) => validPassword(text)}
secureTextEntry={visiblePassword}
style={styles.textInputShadow}
style={styles1.textInputShadow}
/>
<PasswordShowButton
onPress={() => setVisiblePassword(!visiblePassword)}
Expand All @@ -125,7 +126,7 @@ const SignupPage = ({ navigation: { navigate } }) => {
<CustomButtonText>회원가입</CustomButtonText>
</CustomButton>
</FormContainer>
</SafeAreaView>
</PageContainer>
);
};

Expand Down Expand Up @@ -191,7 +192,7 @@ const CustomButton = styled.TouchableOpacity`
border-radius: 16px;
`;

const styles = StyleSheet.create({
const styles1 = StyleSheet.create({
textInputShadow: {
...Platform.select({
ios: {
Expand All @@ -209,13 +210,6 @@ const styles = StyleSheet.create({
},
}),
},
screenArea: {
...Platform.select({
android: {
paddingTop: 20,
},
}),
},
});

//
Expand Down

0 comments on commit e45a0a5

Please sign in to comment.