こんにちは私はネイティブに反応するために新しいです、私はudemyからコースをフォローしています。コースではカスタムボタンを作成している間、ボタンの高さがヌルになっていますが、コースインストラクターによればボタンの高さが必要です。以下は touchableOpacityのヌルの高さを取得
は以下Button.jsここimport React from 'react';
import { Text, TouchableOpacity } from 'react-native';
const Button = ({onPress, children}) => {
return (
<TouchableOpacity onPress={onPress} style={styles.buttonStyle}>
<Text style={styles.textStyle}> {children} </Text>
</TouchableOpacity>
);
};
const styles = {
buttonStyle: {
flex: 1,
alignSelf: 'stretch',
backgroundColor: '#fff',
borderRadius: 5,
borderWidth: 1,
borderColor: '#007aff',
marginLeft: 5,
marginRight: 5
},
textStyle: {
fontSize: 16,
paddingTop: 10,
paddingBottom: 10,
color: '#007aff',
fontWeight: '600'
}
};
export {Button} ;
がされている
import React, { Component } from 'react';
import { View, Text } from 'react-native';
import firebase from 'firebase';
import { Header, Button, Spinner } from './components/common';
import LoginForm from './components/LoginForm';
class App extends Component {
state = { loggedIn: null };
componentWillMount() {
firebase.initializeApp({
apiKey: 'AIzaSyB9AnPpTlaO5XbzPOhPPVBhCbn0SEel7hw',
authDomain: 'authentication-ce600.firebaseapp.com',
databaseURL: 'https://authentication-ce600.firebaseio.com',
projectId: 'authentication-ce600',
storageBucket: 'authentication-ce600.appspot.com',
messagingSenderId: '979192009377'
});
firebase.auth().onAuthStateChanged((user) => {
if (user){
this.setState({ loggedIn: true });
}
else{
this.setState({ loggedIn: false });
}
});
}
renderContent(){
switch (this.state.loggedIn) {
case true:
return (
<Button>
Log Out
</Button>
);
case false:
return <LoginForm />;
default:
return <Spinner size="large" />;
}
}
render(){
return (
<View>
<Header headerText="Auth"/>
{this.renderContent()}
</View>
);
}
};
export default App;
App.js
のソースコードで期待される出力はどうあるべきか:はこれがあります私が得ている実際の出力:
それはapp.js
内の親<View></View>
内のすべてのスペースを占めるので、あなたの<Header />
は、いくつかの高さを持っている必要がありますので、事前
ありがとう...タグiボタンを表示することができますが、特定の値をハードコードすることによって、異なるスクリーンサイズに異なる表現が存在することはありません。とにかくWeb用のブートストラップのようなものはありませんか? –
正しい観察。応答ボタンを作成するには、flexだけを使用する必要があります。一般的な規則は、親がすべての画面スペースを占有し、独自のフレックス値を使用して子どもの間でスペースを分割することです。別の方法は、画面の幅と高さに関して高さと幅を使用することです。反応したネイティブでDimensions APIを使用して画面の寸法を取得できます。次に、画面の高さの3分の1をボタンの高さに設定します。 https://facebook.github.io/react-native/docs/dimensions.html –