如何使用2.10.4在react-native中使stackNavigator背景透明

kupeojn6  于 2022-11-17  发布在  React
关注(0)|答案(1)|浏览(121)

我创建了这个包含路线的homeStack.js文件。我想使用一个自定义背景,但是导航器覆盖了它,我似乎不能修复它。
这是我的博客

import { createStackNavigator } from "react-navigation-stack"
import { createAppContainer } from "react-navigation"
import Home from '../components/Home'
import Detail from '../components/Detail'

const screens = {
    Home: {
        screen: Home,
    },
    Detail: {
        screen: Detail
    },
}


const HomeStack = createStackNavigator(screens, {
    defaultNavigationOptions: {
        headerShown: false
    },
});

export default createAppContainer(HomeStack);

这是app.js,我尝试在这里设置我的背景

import { StyleSheet,View,ImageBackground} from 'react-native';
import Navigator from './routes/homeStack'

export default function App() {
  // const image = { uri: "./assets/background.jpg" };
  const image = require( "./assets/background.jpg");

  return (
    <View style={styles.container}>
      <ImageBackground style={{height:"100%"}} source={image}>
      <Navigator />
      </ImageBackground>
      
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#E8EAED',
  },
});

I want to disable the navigator background so I can use a custom one. I was unable to turn it off.

rryofs0p

rryofs0p1#

使用此方法:

const Stack = createNativeStackNavigator();

const StackNavigator = () => {
  return (
    <Stack.Navigator
      screenOptions={{headerShown: false}}
      initialRouteName="Home">
      <Stack.Screen name="Home" component={Homescreen} />
    </Stack.Navigator>
  );
};

相关问题