javascript - Is it possible to animate a Modal with Animated in React Native? - Stack Overflow

I'm trying to make my Modal slide up and bounce on button click, but it's not working when I

I'm trying to make my Modal slide up and bounce on button click, but it's not working when I wrap the Modal into an Animated.View ponent. It's only sliding up because of the animationType prop but afterwards nothing happens. Any ideas?

   //in render() function
   <Animated.View
    style={{
      flex: 1,
      transform: [                        // `transform` is an ordered array
        { scale: this.state.bounceValue },  // Map `bounceValue` to `scale`
      ],
    }}
    >
      <Modal
        animationType={"slide"}
        transparent={true}
        visible={this.state.modalVisible}
      >
       <View style={styles.modalContainer}>
        <View style={styles.modalInnerContainer}>
          <ListView
            dataSource={this.state.dataSource}
            renderRow={this.renderRow}
          />
        </View>
       </View>
      </Modal>
    </Animated.View>


// onPress function
_onSelectFilter(rowID) {
 if (this.state.modalVisible) {
   this.state.bounceValue.setValue(2);
   Animated.spring(
       this.state.bounceValue,
     {
       toValue: 0.8,
       friction: 1,
     }
     ).start();
  }
}

I'm trying to make my Modal slide up and bounce on button click, but it's not working when I wrap the Modal into an Animated.View ponent. It's only sliding up because of the animationType prop but afterwards nothing happens. Any ideas?

   //in render() function
   <Animated.View
    style={{
      flex: 1,
      transform: [                        // `transform` is an ordered array
        { scale: this.state.bounceValue },  // Map `bounceValue` to `scale`
      ],
    }}
    >
      <Modal
        animationType={"slide"}
        transparent={true}
        visible={this.state.modalVisible}
      >
       <View style={styles.modalContainer}>
        <View style={styles.modalInnerContainer}>
          <ListView
            dataSource={this.state.dataSource}
            renderRow={this.renderRow}
          />
        </View>
       </View>
      </Modal>
    </Animated.View>


// onPress function
_onSelectFilter(rowID) {
 if (this.state.modalVisible) {
   this.state.bounceValue.setValue(2);
   Animated.spring(
       this.state.bounceValue,
     {
       toValue: 0.8,
       friction: 1,
     }
     ).start();
  }
}
Share Improve this question edited Aug 10, 2016 at 7:59 damir46 asked Aug 10, 2016 at 7:53 damir46damir46 671 gold badge2 silver badges7 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

It's not entirely clear in the docs, but <Modal/> in React Native is contained in a native-level view separate from your main React Native container. This means you don't have much control over it.

If you need additional control, you'll need to use a top-level view and not <Modal/>.

If your app is simple, you can simply add a view with absolute positioning at the root level.

// Modal content goes inside here
<View style={{position: 'absolute', top: 0, right: 0, bottom: 0, left: 0}}>
</View>

With more plex apps, you might want to integrate this into your Navigation strategy.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744399640a4572321.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信