React Native文件名

huangapple go评论69阅读模式
英文:

React Native file name

问题

如何移除那个额外的导航栏,上面写着"index"?
尝试了3天仍然搞不清楚为什么只使用Stack屏幕时没有额外的索引。我尝试使用,索引就会出现。
我按照文档的要求,只有一个空项目,但文件名仍然显示在顶部。
有人遇到Drawer的相同问题吗?

React Native文件名

<Drawer.Navigator initialRouteName="Home"
                  screenOptions={({ route }) => ({
                      drawerLabel: () => null, // 隐藏默认页面名称标签
                      drawerIcon: ({ focused }) => (
                          // 您也可以在此处渲染一个图标,而不是名称
                          <CustomDrawerScreen name={route.name} />
                      ),
                  })}

        >
            <Drawer.Screen name="Home" component={HomeContent} />
</Drawer.Navigator>
export default function HomeContent(){

    return (
        <SafeAreaView style={{flex: 1, backgroundColor: "#FAFAFC"}}>
            <Stack.Screen
                options={
                    {
                        headerStyle: {
                            backgroundColor: COLORS.primary
                        },
                        headerShadowVisible: false,
                        headerLeft: () => (
                            <TouchableOpacity style={{
                                width: 40, height: 40, justifyContent: "center",
                                alignItems: "center", backgroundColor: "#ffffff", padding: 4, borderRadius: SIZES.medium,
                            }}
                                              onPress={(navigation) => {
                                                  navigation.openDrawer()
                                              }}
                            >
                                <Image
                                    style={{
                                        width: "70%",
                                        height: "70%",
                                    }}
                                    source={menu}
                                    resizeMode="contain"
                                />

                            </TouchableOpacity>
                        ),
                        headerRight: () => (
                            <TouchableOpacity style={{
                                width: 40, height: 40, justifyContent: "center",
                                alignItems: "center", backgroundColor: "#ffffff", padding: 4, borderRadius: SIZES.medium,
                            }}>
                                <Image
                                    style={{
                                        width: "70%",
                                        height: "70%",
                                    }}
                                    source={notify}
                                    resizeMode="contain"
                                />
                            </TouchableOpacity>
                        ),
                        headerTitle: ""
                    }
                }>
            </Stack.Screen>

            <View style={{marginBottom: 100}}>
                <Svg
                    style={{position: "absolute", top: -68}}
                    height="300"
                    viewBox="0 0 1315 605"
                    width="100%"
                    dimension={"100%"}
                >
                    <Path
                        fill={COLORS.primary}
                        d={'M0,160L21.8,138.7C43.6,117,87,75,131,85.3C174.5,96,218,160,262,165.3C305.5,171,349,117,393,122.7C436.4,128,480,192,524,213.3C567.3,235,611,213,655,192C698.2,171,742,149,785,144C829.1,139,873,149,916,144C960,139,1004,117,1047,138.7C1090.9,160,1135,224,1178,208C1221.8,192,1265,96,1309,48C1352.7,0,1396,0,1418,0L1440,0L1440,0L1418.2,0C1396.4,0,1353,0,1309,0C1265.5,0,1222,0,1178,0C1134.5,0,1091,0,1047,0C1003.6,0,960,0,916,0C872.7,0,829,0,785,0C741.8,0,698,0,655,0C610.9,0,567,0,524,0C480,0,436,0,393,0C349.1,0,305,0,262,0C218.2,0,175,0,131,0C87.3,0,44,0,22,0L0,0Z'}
                    />
                </Svg>


                <View style={{
                    width: "100%",
                    position: "absolute",
                    top: 60,
                    left: 20,
                    paddingBottom: 5
                }}>

                    <Text style={{
                        fontSize: SIZES.medium,
                    }}>
                        你好 David
                    </Text>
                    <Text style={{
                        fontWeight: "bold",
                        fontSize: SIZES.medium,
                    }}>
                        你的观看列表今天
                    </Text>

                    <TouchableOpacity style={{
                        width: 40, height: 40, justifyContent: "center",
                        alignItems: "center", backgroundColor: COLORS.primary, padding: 4, borderRadius: SIZES.medium,
                        position: "absolute",

                        right: 45,
                    }}>
                        <Image
                            style={{
                                width: "70%",
                                height: "70%",
                            }}
                            source={add}
                            resizeMode="contain"
                        />
                    </TouchableOpacity>


                </View>

            </View>
            <View style={{
                flex: 1,
                padding: SIZES.medium,
                justifyContent: "center"
            }}>

                {isLoading ? <ActivityIndicator size="large" color={COLORS.primary}/>
                    : error ? (
                        <Text>出错了</Text>
                    ) : data.length === 0 ?
                        (
                            <View style={{
                                flex: 1,
                                width: "100%",
                                padding: SIZES.medium,
                                justifyContent: "center",
                                alignItems: "center",

                            }}>
                                <View style={{
                                    backgroundColor: COLORS.secondary,
                                    padding: 20,
                                    borderRadius: 10
                                }}>
                                    <Text style={{
                                        color: COLORS.white,
                                        fontWeight: 600
                                    }}

                                    >没有可用数据</Text>
                                </View>

                            </View>

                        ) : (
                            <FlatList data={data} renderItem={({item}) => (
                                <TouchableOpacity style={{
                                    backgroundColor: COLORS.thirty,
                                    borderRadius: 10,
                                    margin: 5,
                                    shadowColor: COLORS.primary,
                                    shadowOffset: {
                                        width: 0,
                                        height: 2,
                                    },
                                    shadowOpacity: 0.5,
                                    shadowRadius: 3.84,
                                    elevation: 5,
                                    padding: SIZES.small,
                                }}>
                                    <View style={{
                                        flex: 1,
                                        justifyContent: "space-between",
                                        flexDirection: "row",
                                        borderRadius: SIZES.small,
                                        backgroundColor: "#FFF",
                                        shadowColor: COLORS.white,
                                        alignItems: "center"
                                    }}>
                                        <View
                                            style={{
                                                width: 50,
                                                height: 50,
                                                backgroundColor: "#FFF",
                                                borderRadius: SIZES.medium,
                                                justifyContent: "center"
                                            }}
                                        >
                                            <Image

<details>
<summary>英文:</summary>

How to remove that extra navigation bar where is saying index? 
3 days trying to figure it out Can&#39;t understand why when I use just Stack screen no extra index . I just try use &lt;Drawer&gt; index appears  . 
I follow docs with just empty project same thing there name file displayed on top 
Any one had same issues with Drawer ?



[![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/y92ne.png





       &lt;Drawer.Navigator initialRouteName=&quot;Home&quot;
                              screenOptions={({ route }) =&gt; ({
                                  drawerLabel: () =&gt; null, // Hide the default page name label
                                  drawerIcon: ({ focused }) =&gt; (
                                      // You can also render an icon here instead of the name
                                      &lt;CustomDrawerScreen name={route.name} /&gt;
                                  ),
                              })}

            &gt;
                &lt;Drawer.Screen name=&quot;Home&quot; component={HomeContent} /&gt;
            &lt;/Drawer.Navigator&gt;
    export default function HomeContent(){

    return (
        &lt;SafeAreaView style={{flex: 1, backgroundColor: &quot;#FAFAFC&quot;}}&gt;
            &lt;Stack.Screen
                options={
                    {
                        headerStyle: {
                            backgroundColor: COLORS.primary
                        },
                        headerShadowVisible: false,
                        headerLeft: () =&gt; (
                            &lt;TouchableOpacity style={{
                                width: 40, height: 40, justifyContent: &quot;center&quot;,
                                alignItems: &quot;center&quot;, backgroundColor: &quot;#ffffff&quot;, padding: 4, borderRadius: SIZES.medium,
                            }}
                                              onPress={(navigation) =&gt; {
                                                  navigation.openDrawer()
                                              }}
                            &gt;
                                &lt;Image
                                    style={{
                                        width: &quot;70%&quot;,
                                        height: &quot;70%&quot;,
                                    }}
                                    source={menu}
                                    resizeMode=&quot;contain&quot;
                                /&gt;

                            &lt;/TouchableOpacity&gt;
                        ),
                        headerRight: () =&gt; (
                            &lt;TouchableOpacity style={{
                                width: 40, height: 40, justifyContent: &quot;center&quot;,
                                alignItems: &quot;center&quot;, backgroundColor: &quot;#ffffff&quot;, padding: 4, borderRadius: SIZES.medium,
                            }}&gt;
                                &lt;Image
                                    style={{
                                        width: &quot;70%&quot;,
                                        height: &quot;70%&quot;,
                                    }}
                                    source={notify}
                                    resizeMode=&quot;contain&quot;
                                /&gt;
                            &lt;/TouchableOpacity&gt;
                        ),
                        headerTitle: &quot;&quot;
                    }
                }&gt;
            &lt;/Stack.Screen&gt;

            &lt;View style={{marginBottom: 100}}&gt;
                &lt;Svg
                    style={{position: &quot;absolute&quot;, top: -68}}
                    height=&quot;300&quot;
                    viewBox=&quot;0 0 1315 605&quot;
                    width=&quot;100%&quot;
                    dimension={&quot;100%&quot;}
                &gt;
                    &lt;Path
                        fill={COLORS.primary}
                        d={&#39;M0,160L21.8,138.7C43.6,117,87,75,131,85.3C174.5,96,218,160,262,165.3C305.5,171,349,117,393,122.7C436.4,128,480,192,524,213.3C567.3,235,611,213,655,192C698.2,171,742,149,785,144C829.1,139,873,149,916,144C960,139,1004,117,1047,138.7C1090.9,160,1135,224,1178,208C1221.8,192,1265,96,1309,48C1352.7,0,1396,0,1418,0L1440,0L1440,0L1418.2,0C1396.4,0,1353,0,1309,0C1265.5,0,1222,0,1178,0C1134.5,0,1091,0,1047,0C1003.6,0,960,0,916,0C872.7,0,829,0,785,0C741.8,0,698,0,655,0C610.9,0,567,0,524,0C480,0,436,0,393,0C349.1,0,305,0,262,0C218.2,0,175,0,131,0C87.3,0,44,0,22,0L0,0Z&#39;}
                    /&gt;
                &lt;/Svg&gt;


                &lt;View style={{
                    width: &quot;100%&quot;,
                    position: &quot;absolute&quot;,
                    top: 60,
                    left: 20,
                    paddingBottom: 5
                }}&gt;

                    &lt;Text style={{
                        fontSize: SIZES.medium,
                    }}&gt;
                        Hello David
                    &lt;/Text&gt;
                    &lt;Text style={{
                        fontWeight: &quot;bold&quot;,
                        fontSize: SIZES.medium,
                    }}&gt;
                        Your watch list today
                    &lt;/Text&gt;

                    &lt;TouchableOpacity style={{
                        width: 40, height: 40, justifyContent: &quot;center&quot;,
                        alignItems: &quot;center&quot;, backgroundColor: COLORS.primary, padding: 4, borderRadius: SIZES.medium,
                        position: &quot;absolute&quot;,

                        right: 45,
                    }}&gt;
                        &lt;Image
                            style={{
                                width: &quot;70%&quot;,
                                height: &quot;70%&quot;,
                            }}
                            source={add}
                            resizeMode=&quot;contain&quot;
                        /&gt;
                    &lt;/TouchableOpacity&gt;


                &lt;/View&gt;

            &lt;/View&gt;
            &lt;View style={{
                flex: 1,
                padding: SIZES.medium,
                justifyContent: &quot;center&quot;
            }}&gt;

                {isLoading ? &lt;ActivityIndicator size=&quot;large&quot; color={COLORS.primary}/&gt;
                    : error ? (
                        &lt;Text&gt;Something went wrong&lt;/Text&gt;
                    ) : data.length === 0 ?
                        (
                            &lt;View style={{
                                flex: 1,
                                width: &quot;100%&quot;,
                                padding: SIZES.medium,
                                justifyContent: &quot;center&quot;,
                                alignItems: &quot;center&quot;,

                            }}&gt;
                                &lt;View style={{
                                    backgroundColor: COLORS.secondary,
                                    padding: 20,
                                    borderRadius: 10
                                }}&gt;
                                    &lt;Text style={{
                                        color: COLORS.white,
                                        fontWeight: 600
                                    }}

                                    &gt;No data available&lt;/Text&gt;
                                &lt;/View&gt;

                            &lt;/View&gt;

                        ) : (
                            &lt;FlatList data={data} renderItem={({item}) =&gt; (
                                &lt;TouchableOpacity style={{
                                    backgroundColor: COLORS.thirty,
                                    borderRadius: 10,
                                    margin: 5,
                                    shadowColor: COLORS.primary,
                                    shadowOffset: {
                                        width: 0,
                                        height: 2,
                                    },
                                    shadowOpacity: 0.5,
                                    shadowRadius: 3.84,
                                    elevation: 5,
                                    padding: SIZES.small,
                                }}&gt;
                                    &lt;View style={{
                                        flex: 1,
                                        justifyContent: &quot;space-between&quot;,
                                        flexDirection: &quot;row&quot;,
                                        borderRadius: SIZES.small,
                                        backgroundColor: &quot;#FFF&quot;,
                                        shadowColor: COLORS.white,
                                        alignItems: &quot;center&quot;
                                    }}&gt;
                                        &lt;View
                                            style={{
                                                width: 50,
                                                height: 50,
                                                backgroundColor: COLORS.white,
                                                borderRadius: SIZES.medium,
                                                justifyContent: &quot;center&quot;
                                            }}
                                        &gt;
                                            &lt;Image
                                                style={{
                                                    width: &quot;70%&quot;,
                                                    height: &quot;70%&quot;,
                                                }}
                                                source={photo}
                                            /&gt;

                                        &lt;/View&gt;
                                        &lt;View style={{
                                            flex: 1,
                                            justifyContent: &quot;center&quot;
                                        }}&gt;
                                            &lt;Text&gt;{item.name}&lt;/Text&gt;
                                            &lt;Text&gt;20 y.o&lt;/Text&gt;
                                        &lt;/View&gt;


                                        &lt;TouchableOpacity style={{
                                            width: 30,
                                            height: 30,
                                            justifyContent: &quot;center&quot;,
                                            alignItems: &quot;center&quot;,
                                            borderWidth: 1,
                                            borderColor: COLORS.primary,
                                            borderRadius: SIZES.small,
                                        }}&gt;

                                            &lt;MaterialCommunityIcons name=&quot;check&quot; size={24} color={COLORS.secondary}
                                                                    onPress={() =&gt; {
                                                                        console.log(item.name)
                                                                    }}
                                            /&gt;
                                        &lt;/TouchableOpacity&gt;

                                    &lt;/View&gt;

                                &lt;/TouchableOpacity&gt;
                            )}

                                      keyExtractor={item =&gt; item?.id}
                                      contentContainerStyle={{columnGap: SIZES.xSmall}}
                                      vertical
                            /&gt;
                        )
                }


            &lt;/View&gt;


        &lt;/SafeAreaView&gt;
    );
}

</details>


# 答案1
**得分**: 0

主要是_layout.js文件位于应用程序文件夹中包裹了整个项目

要移除标题可以使用以下代码

```jsx
screenOptions={{
    headerShown: false
}}
英文:

Solution very simple .

main _layout.js file in app folder wraps whole project.

To remove header

screenOptions={{
headerShown: false
}}

huangapple
  • 本文由 发表于 2023年7月31日 21:25:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76804097.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定