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

Use Header.HEIGHT instead of measuring to avoid flicker #3940

Merged
merged 2 commits into from Apr 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -77,7 +77,6 @@ exports[`StackNavigator applies correct values when headerRight is present 1`] =
</View>
<View
collapsable={undefined}
onLayout={[Function]}
style={
Object {
"transform": Array [
Expand Down Expand Up @@ -278,7 +277,6 @@ exports[`StackNavigator renders successfully 1`] = `
</View>
<View
collapsable={undefined}
onLayout={[Function]}
style={
Object {
"transform": Array [
Expand Down
11 changes: 1 addition & 10 deletions src/views/Header/Header.js
Expand Up @@ -47,12 +47,6 @@ class Header extends React.PureComponent {
widths: {},
};

_handleOnLayout = e => {
if (typeof this.props.onLayout === 'function') {
this.props.onLayout(e.nativeEvent.layout);
}
};

_getHeaderTitleString(scene) {
const options = scene.descriptor.options;
if (typeof options.headerTitle === 'string') {
Expand Down Expand Up @@ -494,10 +488,7 @@ class Header extends React.PureComponent {
const forceInset = headerForceInset || { top: 'always', bottom: 'never' };

return (
<Animated.View
style={this.props.layoutInterpolator(this.props)}
onLayout={this._handleOnLayout}
>
<Animated.View style={this.props.layoutInterpolator(this.props)}>
<SafeAreaView forceInset={forceInset} style={containerStyles}>
<View style={StyleSheet.absoluteFill}>
{options.headerBackground}
Expand Down
10 changes: 3 additions & 7 deletions src/views/StackView/StackViewLayout.js
Expand Up @@ -94,11 +94,7 @@ class StackViewLayout extends React.Component {
}

// Handle the case where the header option is a function, and provide the default
const renderHeader =
header ||
(props => (
<Header onLayout={layout => (this._headerLayout = layout)} {...props} />
));
const renderHeader = header || (props => <Header {...props} />);

const {
headerLeftInterpolator,
Expand Down Expand Up @@ -453,8 +449,8 @@ class StackViewLayout extends React.Component {
const hasHeader = options.header !== null;
const headerMode = this._getHeaderMode();
let marginTop = 0;
if (!hasHeader && headerMode === 'float' && this._headerLayout) {
marginTop = -this._headerLayout.height;
if (!hasHeader && headerMode === 'float') {
marginTop = -Header.HEIGHT;
}

return (
Expand Down