小编tua*_*ran的帖子

如何在TabNavigator上锁定特定屏幕的方向

我用于TabNavigation我的应用程序.在某些屏幕中,我希望它仅在portrait方向上显示,而其他屏幕则显示landscape.我react-native-orientation在屏幕上找到并尝试:

屏幕1

import React from "react";
import Orientation from 'react-native-orientation';
import { Text } from 'react-native'

export default Screen1 extends React.PureComponent{

 componentDidMount(){
  Orientation.lockToLandscape();
 }

 componentWillUnmount(){
  Orientation.unlockAllOrientations();
 }

 render() {
  return(<Text>Screen 1</Text>);
 }
}
Run Code Online (Sandbox Code Playgroud)

屏幕2

import React from "react";
import Orientation from 'react-native-orientation';
import { Text } from 'react-native'

export default Screen2 extends React.PureComponent{

 componentDidMount(){
  Orientation.lockToPortrait();
 }

 componentWillUnmount(){
  Orientation.unlockAllOrientations();
 }

 render() {
  return(<Text>Screen 2</Text>);
 }
}
Run Code Online (Sandbox Code Playgroud)

标签导航器

const AppNavigator = TabNavigator(  {
  Screen1: …
Run Code Online (Sandbox Code Playgroud)

react-native react-navigation

11
推荐指数
1
解决办法
903
查看次数

标签 统计

react-native ×1

react-navigation ×1