3

I'm using react-navigation in my react-native project in order to handle my navigation and routes.

In my case, i have a ViewA and a ViewB.

The ViewA needs informations that i'm filling in my ViewB.

The userflow is ViewA -> ViewB -> ViewA.

** VIEW A **
import React from "react";
import { Button, Text, View } from "react-native";

class ViewA extends React.Component {
  state = { selected: false };

  onSelect = data => {
    this.setState(data);
  };

  onPress = () => {
    this.props.navigate("ViewB", { onSelect: this.onSelect });
  };

  render() {
    return (
      <View>
        <Text>{this.state.selected ? "Selected" : "Not Selected"}</Text>
        <Button title="Next" onPress={this.onPress} />
      </View>
    );
  }
}

.

**VIEW B**
import React from "react";
import { Button } from "react-native";

class ViewB extends React.Component {
  goBack() {
    const { navigation } = this.props;
    navigation.goBack();
    navigation.state.params.onSelect({ selected: true });
  }

  render() {
    return <Button title="back" onPress={this.goBack} />;
  }
}

What i'm trying to do is : Instead of opening my ViewB from left to right, i'd like it to be opened from bottom to up ('above' the ViewA) and having a close transition 'top-bottom'. Such as a Modal.

My issue is, i want to keep my StackNavigator as it is. And would like to custom this transition.

I don't want a Modal.

Thanks for your time and your help

1
  • Have you looked at the transitioner ? Commented Dec 28, 2017 at 14:38

1 Answer 1

4

Make sure you import this at the top of your page

import CardStackStyleInterpolator from "react-navigation/src/views/CardStack/CardStackStyleInterpolator";

This is what your navigator should look like for simple transitions.

StackNavigator(
 {
   Scenes...
 },
 {
   transitionConfig: () => ({
     screenInterpolator: props => {

       // Basically you need to create a condition for individual scenes
       if (props.scene.route.routeName === 'NameOfOneScene') {

         // forVertical makes the scene transition for Top to Bottom
         return CardStackStyleInterpolator.forVertical(props);
       }

       const last = props.scenes[props.scenes.length - 1];

       // This controls the transition when navigation back toa specific scene
       if (last.route.routeName === 'NameOfOneScene') {

         // Here, forVertical flows from Top to Bottom
         return CardStackStyleInterpolator.forVertical(props);
       }

       This declares the default transition for every other scene
       return CardStackStyleInterpolator.forHorizontal(props);
    },
    navigationOptions: { 
      ... 
    },
    cardStyle: {
      ...
    }
 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.