导航上显示空白

问题描述 投票:0回答:1

[以前,我使用切换来处理导航。现在,我切换到useNavigation挂钩。我从一页移动到另一页,如下所示:

<TouchableOpacity
      onPress={() => {
        if (title == 'h') {
          navigation.navigate('AddFriend');
        }
      }}>

[在导航到屏幕时,即使原始设计没有此空白,我仍在底部看到一个空白区域。但是,当我单击Cancel按钮时,空格消失了,页面将根据其应有的格式进行格式化,然后导航回到原始页面。为什么显示空白?如何删除?enter image description here

enter image description here

这是我的AddFriend页面的代码如下:

type AddFriendPageProps = {
  toggleShowPage: () => void;
  showAddFriendPage: boolean;
};

export const AddFriendPage: React.FunctionComponent<AddFriendPageProps> = ({
  toggleShowPage,
  showAddFriendPage,
}) => {
  const [showAddFriendPhonePage, setShowAddFriendPhonePage] = useState(false);
  const navigation = useNavigation();

  const toggleAddFriendPhonePage = () => {
    setShowAddFriendPhonePage(showAddFriendPhonePage ? false : true);
  };

  return (
    <Modal 
    visible={showAddFriendPage} 
    animationType="slide" transparent={true}>
      <SafeAreaView>
        <View style={styles.container}>
          <View style={styles.searchTopContainer}>
            <View style={styles.searchTopTextContainer}>
              <Text
                style={styles.searchCancelDoneText}
                onPress={() => navigation.navigate('Home')}
                >
                Cancel
              </Text>
              <Text style={styles.searchTopMiddleText}>Add Friend</Text>
              <Text style={styles.searchCancelDoneText}>Done</Text>
            </View>
            <View style={styles.searchFieldContainer}>
              <View style={styles.buttonContainer}>
                <Button
                  rounded
                  style={styles.button}
                  onPress={() => setShowAddFriendPhonePage(true)}>
                  <Text style={styles.text}>Add by Phone Number</Text>
                </Button>
              </View>
            </View>
          </View>
          <AddFriendPhonePage
            showAddFriendPhonePage={showAddFriendPhonePage}
            toggleShowPage={toggleAddFriendPhonePage}
          />
        </View>
      </SafeAreaView>
    </Modal>
  );
};
javascript typescript react-native react-hooks react-navigation
1个回答
0
投票

该空白由safeAreaView添加。如果要使safeAreaView具有相同的绿色背景色(必须在其上设置样式或它的父样式),则当前在子View元素上仅具有styles.container

© www.soinside.com 2019 - 2024. All rights reserved.