【发布时间】:2019-08-17 13:52:39
【问题描述】:
我是 React Native 的新手,我正在尝试将我创建的组件垂直和水平居中。如果我将中心样式代码放在整体视图中,它就可以工作,但这也会使 app.js 中心的所有内容。应该有一种方法只使我制作的组件居中。
我已尝试更改 flex 和 diff flexbox 选项。
import React, { Component } from 'react';
import {
Platform,
Animated,
StyleSheet,
Text,
View,
Button,
Alert,
TouchableHighlight,
} from 'react-native';
import Animater from './components/Animater';
import PresentationalComponent from './components/PresentationalComponent';
const AnimatedButton = Animated.createAnimatedComponent(TouchableHighlight);
export default class HelloWorldApp extends Component {
constructor(props) {
super(props);
this.state = {
listDataFromChild: null
};
}
myCallback = (dataFromChild) => {
this.setState({ listDataFromChild: dataFromChild });
}
render() {
return (
<View >
<Text style={styles.score}>
Score: {this.state.listDataFromChild}
</Text>
<View style={styles.container}>
<Animater callbackFromParent={this.myCallback}/>
</View>
</View>
//<PresentationalComponent color = {[animatedStyle]} showAlert = {this.showAlert}/>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
position: 'absolute',
paddingHorizontal: 10,
},
score: {
fontSize: 30,
alignItems: 'center',
top: 100,
},
});
我希望 Animator 组件位于中心,但它却保留在屏幕的左上角
【问题讨论】:
标签: reactjs react-native