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

direction support for rn 0.24+ #503

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions src/DefaultRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ const {
RootContainer: NavigationRootContainer,
Header: NavigationHeader,
} = NavigationExperimental;

const {
CardStackPanResponder: NavigationCardStackPanResponder,
CardStackStyleInterpolator: NavigationCardStackStyleInterpolator
} = NavigationCard;

import Actions from "./Actions";
import getInitialState from "./State";
import Reducer from "./Reducer";
Expand Down Expand Up @@ -49,7 +55,6 @@ export default class DefaultRenderer extends Component {

let applyAnimation = selected.applyAnimation || navigationState.applyAnimation;
let style = selected.style || navigationState.style;
let direction = selected.direction || navigationState.direction || "horizontal";

let optionals = {};
if (applyAnimation) {
Expand All @@ -59,7 +64,11 @@ export default class DefaultRenderer extends Component {
if (duration === null || duration === undefined) duration = navigationState.duration;
if (duration !== null && duration !== undefined) {
optionals.applyAnimation = function (pos, navState) {
Animated.timing(pos, {toValue: navState.index, duration}).start();
if (duration === 0) {
pos.setValue(navState.index);
} else {
Animated.timing(pos, {toValue: navState.index, duration}).start();
}
};
}
}
Expand All @@ -69,7 +78,6 @@ export default class DefaultRenderer extends Component {
navigationState={navigationState}
style={[styles.animatedView, style]}
renderOverlay={this._renderHeader}
direction={direction}
renderScene={this._renderCard}
{...optionals}
/>
Expand All @@ -84,13 +92,22 @@ export default class DefaultRenderer extends Component {
}

_renderCard(/*NavigationSceneRendererProps*/ props) {
const isVertical = props.scene.navigationState.direction === "vertical";

const animationStyle = props.scene.navigationState.animationStyle || (isVertical ?
NavigationCardStackStyleInterpolator.forVertical(props) :
NavigationCardStackStyleInterpolator.forHorizontal(props));

const panHandlers = props.scene.navigationState.panHandlers || (isVertical ?
NavigationCardStackPanResponder.forVertical(props) :
NavigationCardStackPanResponder.forHorizontal(props));

return (
<NavigationCard
{...props}
style={props.scene.navigationState.style}
style={[animationStyle, props.scene.navigationState.style]}
key={"card_" + props.scene.navigationState.key}
direction={props.scene.navigationState.direction || "horizontal"}
panHandlers={props.scene.navigationState.panHandlers }
panHandlers={panHandlers}
renderScene={this._renderScene}
/>
);
Expand Down