最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React Native Navigation Wrap All Screens in a View - Stack Overflow

programmeradmin2浏览0评论

Using react-navigation v5, how does one wrap all screens individually in a scroll view and a keyboard safe view?

export default function App() {
  return (
      <NavigationContainer>
        <Stack.Navigator initialRouteName="Home">
          <Stack.Screen name="Home" ponent={HomeScreen} />
          <Stack.Screen name="Test" ponent={TestScreen} />
        </Stack.Navigator>
      </NavigationContainer>
  );
}

Using react-navigation v5, how does one wrap all screens individually in a scroll view and a keyboard safe view?

export default function App() {
  return (
      <NavigationContainer>
        <Stack.Navigator initialRouteName="Home">
          <Stack.Screen name="Home" ponent={HomeScreen} />
          <Stack.Screen name="Test" ponent={TestScreen} />
        </Stack.Navigator>
      </NavigationContainer>
  );
}
Share Improve this question asked Oct 4, 2020 at 0:46 DynamicDynamic 5071 gold badge10 silver badges17 bronze badges 1
  • Add ScrollView inside the HomeScreen and TestScreen ponent, not in App.js. – SkyTreasure Commented Oct 4, 2020 at 10:24
Add a ment  | 

1 Answer 1

Reset to default 6

Inside navigation container you are only allowed to use Navigator or Screen. So you cannot wrap Stack.Screen with any other ponent.

What you can do is wrap the screen ponent:

Create a new ponent ScreenTemplate maybe, you can decide the name. Then use this ponent to implement your keyboard avoid and scroll logic.

const ScreenTemplate = ({children}) => (
   <AnyWrapperComponent>
      {children}
   </AnyWrapperComponent> 
);

In any other screen:

const HomeScreen = () => (
   <ScreenTemplate>
     //implement anything you want
      <BlaBlaComponent />
    //etc..
   </ScreenTemplate>
);
发布评论

评论列表(0)

  1. 暂无评论