简体   繁体   English

如何在 React Native 中将反应导航堆栈 header 移动到屏幕底部?

[英]How to move react navigation Stack header to bottom of the screen in React native?


I want to show stack header in top for **mobile device** & in bottom of the screen for Tablet screen. 我想在**移动设备**的顶部和平板电脑屏幕的底部显示堆栈 header。 So I tried to move header to bottom of the screen with bellow code. 因此,我尝试使用以下代码将 header 移动到屏幕底部。 but no luck. 但没有运气。 Any pointer would be appreciated. 任何指针将不胜感激。
 <Stack.Screen name="addBusiness" component={BusinessScreen} options={{ title: 'My home', header: (navigationOptions) => ( <View style={{ position: 'relative', bottom: 0, height: 80, width: '100%', backgroundColor: '#dbdbdb', }} > <Text>HOME</Text> </View> ), }} />

You can do something like this:你可以这样做:

import {isTablet} from 'react-native-device-info';
// ...

const headerStyles = () => {
  if (isTablet()) {
    return {
      header: () => (
        <View
          style={{
            position: 'absolute',
            top: Dimensions.get('window').height - 60,
            left: 0,
            right: 0,
            height: 60,
            borderWidth: 1,
            justifyContent: 'center',
            alignItems: 'center',
          }}>
          <Text>HOME</Text>
        </View>
      ),
    };
  }
}

headerStyles can then be used like this: headerStyles然后可以像这样使用:

options={{
  title: 'My home',
  ...headerStyles(),
}}

So you need to import Dimensions from react-native and isTablet from react-native-device-info .所以你需要从react-nativeisTabletreact-native-device-info导入Dimensions


This implementation uses the default react navigation header if the device is not a tablet.如果设备不是平板电脑,此实现使用默认的反应导航 header。 So if you also want to have a custom header on mobile you similarly need to return a header component in an else statement or after the if statement.因此,如果您还想在移动设备上使用自定义 header,您同样需要在 else 语句中或 if 语句之后返回 header 组件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从react-native屏幕上删除导航标题-代码日志 - Remove the navigation header from the react-native screen - stack navigation React Native和React Navigation - 如何在标题和底部标签导航器中显示屏幕标题以显示 - React Native and React Navigation — How to get screen title to show in header and bottom tab navigator to also show 如何将选项卡导航屏幕替换为 React Native 中的堆栈导航屏幕 - How to replace tab navigation screen to stack navigation screen in react native React-Native - 在其中一个屏幕上没有 header(堆栈 + 抽屉导航) - React-Native - no header on one of the screen (Stack + Drawer Navigation) 如何移动到底部选项卡抽屉中的不同屏幕而不在反应原生的选项卡抽屉导航中注册它? - how to move to different screen in bottom tab drawer without registering it in tab drawer navigation in react native? 如何为每个屏幕多堆栈导航创建自定义 header 选项反应原生? - How to create custom header options for each screen multi stack navigation react native? 如何在反应导航的stackNavigator中将标题移到底部? - How to move header to bottom in stackNavigator in react-navigation? 如何在反应本机堆栈 header 中隐藏底部边框线? - How to hide bottom border line in react native stack header? 在主屏幕上反应本地底部导航 - React native bottom navigation in main screen 反应原生底部导航(屏幕 animation ) - React native bottom navigation ( screen animation )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM