Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

Commit

Permalink
Merge pull request #5 from react-navigation/useScreens
Browse files Browse the repository at this point in the history
Use ScreenContainer and Screen components in stack - currently they fallback to RN's View
  • Loading branch information
brentvatne authored Aug 14, 2018
2 parents 094ebbe + 9bfc92b commit d98ae14
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
23 changes: 19 additions & 4 deletions src/views/StackView/StackViewCard.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
import React from 'react';
import { Animated, StyleSheet } from 'react-native';
import { StyleSheet } from 'react-native';
import { Screen } from './screens';
import createPointerEventsContainer from './createPointerEventsContainer';

const EPS = 1e-5;

/**
* Component that renders the scene as card for the <StackView />.
*/
class Card extends React.Component {
render() {
const { children, pointerEvents, style } = this.props;
const {
children,
pointerEvents,
style,
position,
scene: { index },
} = this.props;
const active = position.interpolate({
inputRange: [index, index + 1 - EPS, index + 1],
outputRange: [1, 1, 0],
extrapolate: 'clamp',
});
return (
<Animated.View
<Screen
pointerEvents={pointerEvents}
ref={this.props.onComponentRef}
style={[styles.main, style]}
active={active}
>
{children}
</Animated.View>
</Screen>
);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/views/StackView/StackViewLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {

import Card from './StackViewCard';
import Header from '../Header/Header';
import { ScreenContainer } from './screens';

import TransitionConfigs from './StackViewTransitionConfigs';
import { supportsImprovedSpringAnimation } from '../../utils/ReactNativeFeatures';
Expand Down Expand Up @@ -469,9 +470,9 @@ class StackViewLayout extends React.Component {

return (
<View {...handlers} style={containerStyle}>
<View style={styles.scenes}>
<ScreenContainer style={styles.scenes}>
{scenes.map(s => this._renderCard(s))}
</View>
</ScreenContainer>
{floatingHeader}
</View>
);
Expand Down
6 changes: 6 additions & 0 deletions src/views/StackView/screens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Animated, View } from 'react-native';

const ScreenContainer = View;
const Screen = Animated.View;

export { ScreenContainer, Screen };

0 comments on commit d98ae14

Please sign in to comment.