Skip to content

Commit

Permalink
[#3] style: change Child Button Wrapper View to ScrollView
Browse files Browse the repository at this point in the history
  • Loading branch information
hee-suh committed Jun 3, 2022
1 parent 356da64 commit 491c7ce
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions react-native/screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react';
import { StyleSheet, View, SafeAreaView, TouchableOpacity, ImageBackground, Alert, Image } from 'react-native';
import { StyleSheet, View, SafeAreaView, TouchableOpacity, ImageBackground, Alert, Image, ScrollView } from 'react-native';
import { Text } from 'native-base'
import { theme } from '../core/theme';
import type { Navigation, UserData } from '../types';
Expand All @@ -15,7 +15,7 @@ export default function HomeScreen({ navigation }: Navigation) {
const cProfileImgSource = [require(`../assets/images/cprofile-images/profile-1.png`), require(`../assets/images/cprofile-images/profile-2.png`), require(`../assets/images/cprofile-images/profile-3.png`),
require(`../assets/images/cprofile-images/profile-4.png`), require(`../assets/images/cprofile-images/profile-5.png`), require(`../assets/images/cprofile-images/profile-6.png`), require(`../assets/images/cprofile-images/profile-7.png`), require(`../assets/images/cprofile-images/profile-8.png`), require(`../assets/images/cprofile-images/profile-9.png`)];
const [events, setEvents] = useState<{event_num: number, children: { cid: number, cname: string, cprofileImg: number, events: string[] }[]}>(
{event_num: 4,
{event_num: 2,
children: [
{
cid: 1,
Expand All @@ -40,12 +40,12 @@ export default function HomeScreen({ navigation }: Navigation) {
uid: 1,
username: "Soo",
uemail: "[email protected]",
uprofileImg: 1,
uprofileImg: 0,
ulanguage: "english",
uchildren:[{ cid: 1, cname:"Soo", cprofileImg: 1 }, { cid: 2, cname:"Hee", cprofileImg: 4 }]
});
const auth = useAuth();


useEffect(()=> {
if (auth?.userData) {
Expand Down Expand Up @@ -83,12 +83,6 @@ export default function HomeScreen({ navigation }: Navigation) {
}
}, [auth]);

useEffect(() => {
if (events && events?.children?.length > 0) {
setNowSelectedChildId(events.children[0].cid);
}
}, [events]);

const handleNowSelectedChildId = (cid: number) => {
setNowSelectedChildId(cid);
}
Expand Down Expand Up @@ -119,7 +113,7 @@ export default function HomeScreen({ navigation }: Navigation) {
</ImageBackground>
<View style={styles.noticeWrapper}>
<Text style={styles.smallTitle} fontFamily="heading" fontWeight={700} fontStyle="normal" fontSize="2xl" lineHeight={60}>{i18n.t('todayEvent')}</Text>
<View style={styles.childButtonWrapper}>
<ScrollView horizontal={true} style={styles.childButtonWrapper}>
<TouchableOpacity key={'n_all'} style={[styles.childButton, {
backgroundColor: nowSelectedChildId === SHOW_ALL ? theme.colors.primary : "#ffffff",
}]} onPress={() => handleNowSelectedChildId(-1)}>
Expand All @@ -137,11 +131,11 @@ export default function HomeScreen({ navigation }: Navigation) {
}]}>{child.cname}</Text>
</TouchableOpacity>
)}
</View>
</ScrollView>
<View style={styles.todayNoticeWrapper}>
{nowSelectedChildId === SHOW_ALL ? (
events.children.reduce((prevValue, child) => prevValue + child.events.length, 0) > 0 ? (
events.children.map((notice, index) =>
events?.children.reduce((prevValue, child) => prevValue + child.events.length, 0) > 0 ? (
events?.children.map((notice, index) =>
<View key={'n_'+index}>
{notice.events.map((event, index) => {
return (
Expand All @@ -150,7 +144,7 @@ export default function HomeScreen({ navigation }: Navigation) {
})}
</View>))
: <NoEventBox/>
) : events.children.filter(child => child.cid === nowSelectedChildId)[0].events?.length ? (
) : events.children.filter(child => child.cid === nowSelectedChildId)[0]?.events?.length ? (
events.children?.filter(child => child.cid === nowSelectedChildId)[0].events?.map((item, index) =>
<View key={'e_'+index} style={{flexDirection: "row"}}>
<Text fontSize="md" lineHeight={28}>{index+1 + '. ' + item}</Text>
Expand Down Expand Up @@ -203,7 +197,7 @@ const styles = StyleSheet.create({
},
childButtonWrapper: {
flexDirection: "row",
flexWrap: "wrap",
maxHeight: 40
},
childButton: {
borderWidth: 1,
Expand All @@ -219,7 +213,7 @@ const styles = StyleSheet.create({
},
todayNoticeWrapper: {
alignSelf: "flex-start",
paddingTop: 18,
paddingTop: 8,
paddingHorizontal: 12,
overflow: "scroll",
flex: 1,
Expand Down

0 comments on commit 491c7ce

Please sign in to comment.