@shoutem/ui と react-native exponent フレームワークを使用して、react ネイティブ アプリを作成しています。簡単なことをしたい: スタイル名 'muted' をトグル ボタンが選択されていない場合に追加します。この場合、[ログイン] と [登録] の 2 つのボタンがあり、いずれかをしようとしているかどうかに応じて 1 つがミュートされます。
jsx でインライン条件を実行しようとして、構文に問題があります。私が見たいくつかの例では、クラス オブジェクトを動的に追加していますが、shoutem/ui を使用しているため、className がオブジェクトではなく文字列であるかどうかはわかりません。styleName文字列を追加するかどうかを確認するためにインライン条件を実行することだけを考えていましたが、正しくないようです。
import React, { Component } from 'react';
import {
Image,
Title,
Text,
View,
Button,
TextInput,
Screen,
} from '@shoutem/ui';
export default class LoginScreen extends Component {
constructor(props) {
super(props);
this.state = {
isRegistering: false,
}
}
toggleRegister(registering) {
this.setState({isRegistering:registering});
}
render() {
return (
<Screen styleName="vertical collapsed paper">
<View styleName="md-gutter">
<View styleName="horizontal">
<Button styleName="full-width {this.state.isRegistering ? 'muted' || ''}" onPress={()=>this.toggleRegister(false)}>
<Text>LOGIN</Text>
</Button>
<Button styleName="full-width {this.state.isRegistering ? '' || 'muted'}" onPress={()=>this.toggleRegister(true)}>
<Text>Register</Text>
</Button>
</View>
<TextInput
placeholder="Username or Email"
/>
<TextInput
placeholder="Password"
secureTextEntry
/>
<Button styleName="dark">
<Text>Submit</Text>
</Button>
</View>
</Screen>
);
}
}