最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论