Skip to content

Instantly share code, notes, and snippets.

@mikerodham
Created September 17, 2018 13:21
Show Gist options
  • Save mikerodham/fba1fb6651a4c01bed93a86c8e2a7725 to your computer and use it in GitHub Desktop.
Save mikerodham/fba1fb6651a4c01bed93a86c8e2a7725 to your computer and use it in GitHub Desktop.
Switch
switch(field.type) {
case 'text':
return (
<View key={j}>
<Input containerStyle={[styles.inputContainerStyle]}
ref={(ref) => this.inputRefs[field.name] = ref}
value={this.state.event.cards[i].fields[j].value}
placeholder={field.name}
multiline={false}
placeholderTextColor="#86939e"
inputStyle={{fontSize: 14}}
leftIcon={ this.state.event.cards[i].fields[j].mandatory &&
<Text style={{color: '#ff0000', fontSize: 14, position: 'absolute', left: -15}}>*</Text>
}
leftIconContainerStyle={{ position: this.state.event.cards[i].fields[j].mandatory ? 'absolute': 'relative'}}
returnKeyType='next'
rightIcon={ this.state.event.cards[i].fields[j].disclaimer &&
<Switch value={this.state.event.cards[i].fields[j].optin} onValueChange={() => {
this.setSwitch(i, j, null)
}}/>
}
rightIconContainerStyle={{paddingBottom: 10}}
onSubmitEditing={
() => {
if(this.state.event.cards[i].fields[j+1]) {
if(this.state.event.cards[i].fields[j+1].type === 'text' || this.state.event.cards[i].fields[j+1].type === 'numeric' || this.state.event.cards[i].fields[j+1].type === 'email') {
let name = this.state.event.cards[i].fields[j+1].name;
this.inputRefs[name].focus();
return;
}
}
}
}
onChangeText={(text) => {
let e = this.state.event;
e.cards[i].fields[j].value = text;
e.cards[i].fields[j].error = '';
this.setState({
event: e
});
}}></Input>
{
this.state.event.cards[i].fields[j].disclaimer && this.state.event.cards[i].fields[j].disclaimer_text &&
<Button style={{paddingTop: 5, fontSize: 10, color: '#000000', textAlign: 'left'}}
onPress={() => {
Alert.alert(
'Disclaimer',
this.state.event.cards[i].fields[j].disclaimer_text,
[
{text: 'Decline', onPress: () => this.setSwitch(i, j, false)},
{text: 'Accept', onPress: () => this.setSwitch(i, j, true)}
]
)
}}>
{this.state.event.cards[i].fields[j].disclaimer_text.slice(0, 80)}... Press here to read more
</Button>
}
{ this.state.event.cards[i].fields[j].error && <Text style={{ color: '#e74c3c', fontSize: 14, paddingLeft: 5 }}>
{this.state.event.cards[i].fields[j].error}
</Text>
}
</View>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment