Jo Ko Jo Ko - 1 year ago 170
React JSX Question

How to slide <View/> in and out from the bottom in React Native?

In React Native iOS, I would like to slide in and out a like to following in the picture.

In the following example, when a button is pressed, the

Payment Information
view pops up from the bottom and when the collapse button is pressed, it goes back down and disappears.

What would be the correct and proper way to go about doing so?

enter image description here

Thank you in advance!

Answer Source

Basically, you need to absolute-position your view to the bottom of the screen. Then you translate its y value to equal its height. (The sub view must have a specific height in order to know how much to move it)

Here's a playground showing the result:


'use strict';

import React, {Component} from 'react';
import ReactNative from 'react-native';

const {
} = ReactNative;

var isHidden = true;

class AppContainer extends Component {
  constructor(props) {
    this.state = {
      bounceValue: new Animated.Value(100),  //This is the initial position of the subview
      buttonText: "Show Subview"

  _toggleSubview() {    
      buttonText: !isHidden ? "Show Subview" : "Hide Subview"

    var toValue = 100;

    if(isHidden) {
      toValue = 0;

    //This will animate the transalteY of the subview between 0 & 100 depending on its current state
    //100 comes from the style below, which is the height of the subview.
        toValue: toValue,
        velocity: 3,
        tension: 2,
        friction: 8,

    isHidden = !isHidden;

  render() {
    return (
      <View style={styles.container}>
          <TouchableHighlight style={styles.button} onPress={()=> {this._toggleSubview()}}>
            <Text style={styles.buttonText}>{this.state.buttonText}</Text>
              {transform: [{translateY: this.state.bounceValue}]}]}
            <Text>This is a sub view</Text>

var styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
    marginTop: 66
  button: {
    padding: 8,
  buttonText: {
    fontSize: 17,
    color: "#007AFF"
  subView: {
    position: "absolute",
    bottom: 0,
    left: 0,
    right: 0,
    backgroundColor: "#FFFFFF",
    height: 100,

AppRegistry.registerComponent('AppContainer', () => AppContainer);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download