Merge pull request #20 from janicduplessis/no-neg-margin

Use padding instead of negative margin in StackViewLayout
This commit is contained in:
Brent Vatne
2018-09-14 12:33:57 +02:00
parent 12d4f23bb1
commit 455c5b61e1
3 changed files with 53 additions and 12 deletions

View File

@@ -440,7 +440,11 @@ class StackViewLayout extends React.Component {
if (headerMode === 'float') {
const { scene } = this.props.transitionProps;
floatingHeader = (
<View pointerEvents="box-none" onLayout={this._onFloatingHeaderLayout}>
<View
style={styles.floatingHeader}
pointerEvents="box-none"
onLayout={this._onFloatingHeaderLayout}
>
{this._renderHeader(scene, headerMode)}
</View>
);
@@ -595,22 +599,21 @@ class StackViewLayout extends React.Component {
screenInterpolator &&
screenInterpolator({ ...this.props.transitionProps, scene });
// If this screen has "header" set to `null` in it's navigation options, but
// it exists in a stack with headerMode float, add a negative margin to
// compensate for the hidden header
// When using a floating header, we need to add some top
// padding on the scene.
const { options } = scene.descriptor;
const hasHeader = options.header !== null;
const headerMode = this._getHeaderMode();
let marginTop = 0;
if (!hasHeader && headerMode === 'float') {
marginTop = -this.state.floatingHeaderHeight;
let paddingTop = 0;
if (hasHeader && headerMode === 'float' && !options.headerTransparent) {
paddingTop = this.state.floatingHeaderHeight;
}
return (
<Card
{...this.props.transitionProps}
key={`card_${scene.key}`}
style={[style, { marginTop }, this.props.cardStyle]}
style={[style, { paddingTop }, this.props.cardStyle]}
scene={scene}
>
{this._renderInnerScene(scene)}
@@ -631,6 +634,12 @@ const styles = StyleSheet.create({
scenes: {
flex: 1,
},
floatingHeader: {
position: 'absolute',
left: 0,
top: 0,
right: 0,
},
});
export default withOrientation(StackViewLayout);