react-native – React Native中可调整大小的Flex布局
发布时间:2020-12-15 05:04:40 所属栏目:百科 来源:网络整理
导读:如何在本机中创建可调整大小的布局?像这样: 这是一个演示但是对于ReactJS: https://leefsmp.github.io/Re-Flex/index.html 我也在我的应用程序中遇到了这个问题,并最终以这种方式实现. 希望这可以帮助这种痛苦. https://github.com/brucelin0325/resizabl
如何在本机中创建可调整大小的布局?像这样:
这是一个演示但是对于ReactJS:
我也在我的应用程序中遇到了这个问题,并最终以这种方式实现.
希望这可以帮助这种痛苦. https://github.com/brucelin0325/resizable_layout MyComponent.js import React,{ Component } from 'react'; import { StyleSheet,View,Dimensions,PanResponder,Animated } from 'react-native'; export default class MyComponent extends Component { constructor(props) { super(props); this.state = { offset : 0,topHeight : 40,// min height for top pane header bottomHeight : 40,// min height for bottom pane header,deviceHeight : Dimensions.get('window').height,isDividerClicked: false,pan : new Animated.ValueXY() } } componentWillMount() { this._panResponder = PanResponder.create({ onMoveShouldSetResponderCapture: () => true,onMoveShouldSetPanResponderCapture: () => true,// Initially,set the Y position offset when touch start onPanResponderGrant: (e,gestureState) => { this.setState({ offset: e.nativeEvent.pageY,isDividerClicked: true }) },// When we drag the divider,set the bottomHeight (component state) again. onPanResponderMove: (e,gestureState) => { this.setState({ bottomHeight : gestureState.moveY > (this.state.deviceHeight - 40) ? 40 : this.state.deviceHeight - gestureState.moveY,offset: e.nativeEvent.pageY }) },onPanResponderRelease: (e,gestureState) => { // Do something here for the touch end event this.setState({ offset: e.nativeEvent.pageY,isDividerClicked: false }) } }); } render() { return ( <View style={styles.content}> {/* Top View */} <Animated.View style = {[{backgroundColor: 'pink',minHeight: 40,flex: 1},{height: this.state.topHeight}]} > </Animated.View> {/* Divider */} <View style={[{height: 10},this.state.isDividerClicked ? {backgroundColor: '#666'} : {backgroundColor: '#e2e2e2'}]} {...this._panResponder.panHandlers} > </View> {/* Bottom View */} <Animated.View style={[{backgroundColor: 'green',minHeight: 40},{height: this.state.bottomHeight}]} > </Animated.View> </View> ) } } const styles = StyleSheet.create({ content : { flex : 1,flexDirection: 'column' },}) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |