Commit 74d3ef42 by nguyenquangtung004

TODO: Đã fix thành công SafeAreaView không bị khoảng trắng

parent cd549183
...@@ -6,7 +6,6 @@ const styles = StyleSheet.create({ ...@@ -6,7 +6,6 @@ const styles = StyleSheet.create({
containerBoxHeader: { containerBoxHeader: {
flexDirection: "row", flexDirection: "row",
marginHorizontal: 15, marginHorizontal: 15,
marginTop: 15,
maxHeight: 40, maxHeight: 40,
}, },
boxLogo:{ boxLogo:{
......
...@@ -10,6 +10,8 @@ import { ...@@ -10,6 +10,8 @@ import {
Keyboard, Keyboard,
SafeAreaView, SafeAreaView,
Image, Image,
StatusBar, // FEATURE: Thêm StatusBar để control status bar
Platform, // FEATURE: Check platform để xử lý khác biệt iOS/Android
} from "react-native"; } from "react-native";
import HeaderCus from "../home/header"; import HeaderCus from "../home/header";
import R from "../../assets/R"; import R from "../../assets/R";
...@@ -17,6 +19,7 @@ import ItemGrid from "./item"; ...@@ -17,6 +19,7 @@ import ItemGrid from "./item";
import styles from "./style"; import styles from "./style";
import { useNavigation } from "@react-navigation/native"; import { useNavigation } from "@react-navigation/native";
import * as SCREENNAME from "../../routers/ScreenNames"; import * as SCREENNAME from "../../routers/ScreenNames";
const HomeView = (props) => { const HomeView = (props) => {
const { const {
menuActivity, menuActivity,
...@@ -29,13 +32,18 @@ const HomeView = (props) => { ...@@ -29,13 +32,18 @@ const HomeView = (props) => {
onSearchChange, onSearchChange,
} = props; } = props;
const navigate = useNavigation(); const navigate = useNavigation();
// FUNCTIONALITY: Render menu item với tối ưu performance
const renderMenuItem = ({ item }) => { const renderMenuItem = ({ item }) => {
return <ItemGrid item={item} onPress={() => onMenuItemPress(item)} />; return <ItemGrid item={item} onPress={() => onMenuItemPress(item)} />;
}; };
const cardItemInfo =()=>{
return <View style={styles.profileCard}> // UI/UX: Card thông tin user với layout tối ưu
const cardItemInfo = () => {
return (
<View style={styles.profileCard}>
<View style={styles.profile_left}> <View style={styles.profile_left}>
{/* Avatar */} {/* FEATURE: Avatar với fallback placeholder */}
<View style={styles.avatar}> <View style={styles.avatar}>
{userProfile?.avatar ? ( {userProfile?.avatar ? (
<Image <Image
...@@ -46,46 +54,53 @@ const HomeView = (props) => { ...@@ -46,46 +54,53 @@ const HomeView = (props) => {
) : ( ) : (
<View style={styles.avatar_placeholder}> <View style={styles.avatar_placeholder}>
<Text style={styles.avatar_text}> <Text style={styles.avatar_text}>
{userProfile?.name?.charAt(0)} {userProfile?.name?.charAt(0) || "U"}
</Text> </Text>
</View> </View>
)} )}
</View> </View>
{/* Information */}
{/* FEATURE: Thông tin user với null safety */}
<View style={styles.information}> <View style={styles.information}>
<Text <Text
style={styles.text_card_info} style={styles.text_card_info}
numberOfLines={1} numberOfLines={1}
ellipsizeMode="tail" ellipsizeMode="tail"
> >
{userProfile?.name?? "Không có dữ liệu"} {userProfile?.name ?? "Không có dữ liệu"}
</Text> </Text>
<Text <Text
style={styles.text_card_info} style={styles.text_card_info}
numberOfLines={1} numberOfLines={1}
ellipsizeMode="tail" ellipsizeMode="tail"
> >
{userProfile?.phone??"Không có dữ liệu"} {userProfile?.phone ?? "Không có dữ liệu"}
</Text> </Text>
</View> </View>
</View> </View>
<TouchableOpacity style={styles.profile_btn} onPress={() => navigate.navigate(SCREENNAME.PROFILE)}> {/* FEATURE: Button navigate tới profile */}
<TouchableOpacity
style={styles.profile_btn}
onPress={() => navigate.navigate(SCREENNAME.PROFILE)}
activeOpacity={0.7}
>
<Text style={styles.btn_text}>H sơ cá nhân</Text> <Text style={styles.btn_text}>H sơ cá nhân</Text>
<View style={styles.iconNext}> <View style={styles.iconNext}>
<Image <Image
source={R.images.icNext} source={R.images.icNext}
maxWidth={5} style={{ width: 5, height: 10 }} // OPTIMIZE: Dùng style thay maxWidth/maxHeight
maxHeight={10}
/> />
</View> </View>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
} );
};
const renderMenuActivity =()=>{ // FUNCTIONALITY: Render menu activity với FlatList tối ưu
return <View style={styles.menu_container}> const renderMenuActivity = () => {
return (
<View style={styles.menu_container}>
<Text style={styles.menu_title}>Ging dy</Text> <Text style={styles.menu_title}>Ging dy</Text>
<FlatList <FlatList
data={menuActivity} data={menuActivity}
...@@ -95,11 +110,17 @@ const HomeView = (props) => { ...@@ -95,11 +110,17 @@ const HomeView = (props) => {
scrollEnabled={false} scrollEnabled={false}
columnWrapperStyle={styles.row} columnWrapperStyle={styles.row}
ListEmptyComponent={renderItemEmpty} ListEmptyComponent={renderItemEmpty}
removeClippedSubviews={true} // PERFORMANCE: Tối ưu memory
maxToRenderPerBatch={9} // PERFORMANCE: Render tối đa 9 items/batch
/> />
</View> </View>
} );
const renderMenuStatistics =()=>{ };
return <View style={styles.menu_container}>
// FUNCTIONALITY: Render menu statistics
const renderMenuStatistics = () => {
return (
<View style={styles.menu_container}>
<Text style={styles.menu_title}>Thng kê</Text> <Text style={styles.menu_title}>Thng kê</Text>
<FlatList <FlatList
data={menuStatistics} data={menuStatistics}
...@@ -109,11 +130,17 @@ const HomeView = (props) => { ...@@ -109,11 +130,17 @@ const HomeView = (props) => {
scrollEnabled={false} scrollEnabled={false}
columnWrapperStyle={styles.row} columnWrapperStyle={styles.row}
ListEmptyComponent={renderItemEmpty} ListEmptyComponent={renderItemEmpty}
removeClippedSubviews={true}
maxToRenderPerBatch={9}
/> />
</View> </View>
} );
const renderMenuNotification =()=>{ };
return <View style={styles.menu_container}>
// FUNCTIONALITY: Render menu notification
const renderMenuNotification = () => {
return (
<View style={styles.menu_container}>
<Text style={styles.menu_title}>Văn bn và thông báo</Text> <Text style={styles.menu_title}>Văn bn và thông báo</Text>
<FlatList <FlatList
data={menuNotification} data={menuNotification}
...@@ -123,29 +150,47 @@ const HomeView = (props) => { ...@@ -123,29 +150,47 @@ const HomeView = (props) => {
scrollEnabled={false} scrollEnabled={false}
columnWrapperStyle={styles.row} columnWrapperStyle={styles.row}
ListEmptyComponent={renderItemEmpty} ListEmptyComponent={renderItemEmpty}
removeClippedSubviews={true}
maxToRenderPerBatch={9}
/> />
</View> </View>
} );
};
const renderItemEmpty =()=>{ // UI/UX: Empty state component
return <View style={styles.cardItemEmpty}> const renderItemEmpty = () => {
return (
<View style={styles.cardItemEmpty}>
<Image <Image
source={R.images.icNoData} source={R.images.icNoData}
maxWidth={50} style={{ width: 50, height: 50 }} // OPTIMIZE: Dùng style object
maxHeight={50}
/> />
<Text style={[styles.menu_text,{color:R.colors.red}]}>Không có d liu</Text> <Text style={[styles.menu_text, { color: R.colors.red }]}>
Không có d liu
</Text>
</View> </View>
} );
};
return ( return (
<>
{/* FIXME: StatusBar để control màu status bar và remove white space */}
<StatusBar
barStyle="light-content" // Text trắng trên status bar
backgroundColor="transparent" // Background trong suốt
translucent={true} // Cho phép content hiển thị dưới status bar
/>
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}> <TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
<SafeAreaView style={styles.safeArea}> {/* FIXME: Dùng View thay SafeAreaView để loại bỏ white space */}
<View style={[styles.safeArea, { paddingTop: Platform.OS === 'ios' ? 0 : StatusBar.currentHeight }]}>
<View style={styles.container_body}> <View style={styles.container_body}>
<ImageBackground <ImageBackground
source={R.images.igBackground} source={R.images.igBackground}
style={styles.background_header} style={[styles.background_header, {
// FIXME: Extend background lên trên để cover status bar
paddingTop: Platform.OS === 'ios' ? 50 : (StatusBar.currentHeight || 0) + 10,
}]}
> >
<HeaderCus <HeaderCus
value={searchText} value={searchText}
...@@ -153,18 +198,22 @@ const HomeView = (props) => { ...@@ -153,18 +198,22 @@ const HomeView = (props) => {
/> />
{cardItemInfo()} {cardItemInfo()}
</ImageBackground> </ImageBackground>
<ScrollView <ScrollView
showsVerticalScrollIndicator={false} showsVerticalScrollIndicator={false}
style={styles.scroll}> style={styles.scroll}
bounces={false} // OPTIMIZE: Tắt bounce effect
overScrollMode="never" // OPTIMIZE: Android không over scroll
>
{renderMenuActivity()} {renderMenuActivity()}
{renderMenuStatistics()} {renderMenuStatistics()}
{renderMenuNotification()} {renderMenuNotification()}
</ScrollView> </ScrollView>
</View> </View>
</SafeAreaView> </View>
</TouchableWithoutFeedback> </TouchableWithoutFeedback>
</>
); );
}; };
export default HomeView; export default HomeView;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment