Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable the left-to-right transition animation during initial app launch? #50

Closed
wenbinf opened this issue Jan 27, 2017 · 10 comments

Comments

@wenbinf
Copy link

wenbinf commented Jan 27, 2017

I use TabNavigator and here's the full code:

class HomeScreen extends React.Component {
    render() {
        return <View style={{flexDirection:'row', backgroundColor: 'red', height: 300,
            justifyContent:'flex-end', paddingTop: 30}}>
            <Text>Hello, Navigation!</Text>
        </View>
    }
}

class SecondScreen extends React.Component {
    render() {
        return <View style={{flexDirection:'row', justifyContent:'flex-end', paddingTop: 30}}>
            <Text>Hello, Second!</Text>
        </View>
    }
}

const AppContainer = TabNavigator({
        HomePage: {screen: HomeScreen},
        SecondPage: {screen: SecondScreen}
    }
)

As you can see, when app initially launches, the text "flies" in ... How can I disable this effect?

jan-27-2017 14-00-02

Thanks in advance!

@satya164
Copy link
Member

I think you need to set flex: 1 on your view.

@wenbinf
Copy link
Author

wenbinf commented Jan 27, 2017

Thanks @satya164 , but now it becomes this:

jan-27-2017 14-08-16

I added "flex: 1"

class HomeScreen extends React.Component {
    render() {
        return <View style={{flex: 1, flexDirection:'row', backgroundColor: 'red', height: 300,
            justifyContent:'flex-end', paddingTop: 30}}>
            <Text>Hello, Navigation!</Text>
        </View>
    }
}

btw, StackNavigator and DrawerNavigator don't have this issue. It's only TabNavigator.

@satya164
Copy link
Member

So seems it only happens when you've flexDirection: row. For example, the following works fine,

class HomeScreen extends React.Component {
  render() {
    return (
      <View>
        <View
          style={{
            flexDirection: 'row',
            backgroundColor: 'red',
            height: 300,
            justifyContent: 'flex-end',
            paddingTop: 30,
          }}
        >
          <Text>Hello, Navigation!</Text>
        </View>
      </View>
    );
  }
}

@wenbinf
Copy link
Author

wenbinf commented Jan 27, 2017

hmm ... I ran your code snippet, but it still doesn't work.

The version that I'm using is "react-navigation": "^1.0.0-beta.1".

Let me dig more ...

@satya164
Copy link
Member

@wenbinf hmm. I just tested this on simulator and couldn't reproduce the issue anymore.

@wenbinf
Copy link
Author

wenbinf commented Jan 27, 2017

For the record, this was the environment that I tested

  • node v7.2.1
  • iOS Simulator: iPhone 6 + iOS 8.4 / iOS 10, iPhone 7 + iOS 10.2
  • real iphone 6 + iOS 10.2
  • "react-navigation": "^1.0.0-beta.1"
  • "react-native": "0.40.0",

Just in case someone on the Internet encounters the same problem :)

@hilkeheremans
Copy link

hilkeheremans commented Jan 28, 2017

This is still an issue on latest master as of this post. When testing, please also use react-native-debugger to make sure the embedded chrome debugger doesnt hide the issue.

To reproduce, use a TabNavigator as follows:

export const TestTabAnim = TabNavigator({
        splash: {
            screen: () => (<View style={{ flex: 1, backgroundColor: 'red' }}><Text>Tab 1</Text></View>)
        },
        login: {
            screen: () => (<View style={{ flex: 1, backgroundColor: 'blue' }}><Text>Tab 1</Text></View>)
        },
        home: {
            screen: () => (<View style={{ flex: 1, backgroundColor: 'purple' }}><Text>Tab 1</Text></View>)
        }
    })

I have tracked down the root cause, and it lies within the react-native-tab-view dependency. More specifically, when an AnimatedTabView tries to mount initially, it has no knowledge of the actual dimensions it should render in, and thus has no idea of what to animate to. In order to circumvent this, the TabViewTransitioner component in react-native-tab-view seems to use onLayout to immediately change the animation target to the actual width and height of the view (https://github.com/react-native-community/react-native-tab-view/blob/master/src/TabViewTransitioner.js#L110). This causes a "one frame delay in rendering", which is also what you notice visually.

A not-so-practical workaround to avoid this animation issue would then be to somehow pass the tab navigator's width and height before mount. I tested this hypothesis by directly passing a hardcoded initialLayout={{ height: <height>, width: <width> }} prop to the AnimatedTabView from TabView in react-native-navigation (ie here: https://github.com/react-community/react-navigation/blob/master/src/views/TabView/TabView.js#L184). This resolves the issue albeit not in a very practical way :-).

@satya164 Seems like you are 'the man to talk to' re react-native-tab-view -- any further insights? Thanks!

@satya164
Copy link
Member

satya164 commented Jan 28, 2017

A not-so-practical workaround to avoid this animation issue would then be to somehow pass the tab navigator's width and height before mount

We don't need that. The one frame delay is only for things like indicator which absolutely need the width before rendering. Tab view knows how to handle the layout before measurement is done, so that there is no delay. There were some missing styles in the scrollview based pager that iOS uses, which prevented it from working properly. I just pushed an update with fixed styles.

When testing, please also use react-native-debugger to make sure the embedded chrome debugger doesnt hide the issue

Debuggers often change the behaviour. So it's better not to use any debuggers while testing an issue.

satya164 added a commit that referenced this issue Jan 28, 2017
Fixed scrollview's style so it doesn't need layout satya164/react-native-tab-view@6ef48ed

Fixes #50
@hilkeheremans
Copy link

Thanks!

@wenbinf
Copy link
Author

wenbinf commented Jan 28, 2017

npm install --save react-community/react-navigation
node_modules/react-native/packager/packager.sh --reset-cache

Then it works!

Thanks a lot! @satya164

satya164 pushed a commit that referenced this issue Feb 7, 2020
sourcecode911 pushed a commit to sourcecode911/react-navigation that referenced this issue Mar 9, 2020
Fixed scrollview's style so it doesn't need layout satya164/react-native-tab-view@6ef48ed

Fixes react-navigation#50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants