Skip to content

SwitchNavigator rotates orientation even when it is locked #5442

@vladinko0

Description

@vladinko0

Current Behavior

When I launch application it is rotated to Landscape and then quickly back to Portrait mode.

Expected Behavior

I want to make it stable in Portrait mode on launch. But I cannot lock whole project to Portrait, because on some screens I need Landscape orientation.
This issue is not caused by react-native-orientation-locker module, because when I am not using routes.js file it locks the screen to Portrait without any rotation.

How to reproduce

App.js

import React, { Component } from 'react';
import Start from './routes'
import Orientation from 'react-native-orientation-locker';

export default class App extends Component {
  constructor(props) {
    super(props);
} 
 componentDidMount() {
    Orientation.lockToPortrait(); 
  }
  render() {
    return (
      <Start />
    );
  }
}

routes.js

import { StackNavigator, SwitchNavigator } from 'react-navigation';
import AuthLoadingScreen from './authloading'
import LoginScreen from './loginScreen'
import AppScreen from './appScreen'


const AuthStack = StackNavigator({
    Login: LoginScreen
});

const AppStack = StackNavigator({
    App: AppScreen
});


export default SwitchNavigator(
    {
        AuthLoading: AuthLoadingScreen,
        Auth: AuthStack,
        App: AppStack        
    },
    {
        initialRouteName: 'AuthLoading',
    }
);

authloading.js

import React from 'react';
import {
  View,
  Text
} from 'react-native';
import Orientation from 'react-native-orientation-locker';

export default class AuthLoadingScreen extends React.Component {
  constructor(props) {
    super(props);
  }
  componentDidMount() {
    Orientation.lockToPortrait(); 
  }

  render() {
    return (
      <View >
            <Text>Auth Loading</Text>
      </View>
    );
  }
}

Your Environment

software version
react-navigation 1.5.1
react-native 0.54.0
node
npm or yarn 5.10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions