Я пытаюсь скрыть \ показать tableHead3: ['BANANA']
, который находится на экране "InfoTable" , пометив флажок "BOB" , найденный на "SettingsScreen" . Я новичок в реакции родной, и я не знаю, избыточный. кто-то может показать мне, пожалуйста, как сделать это с моим примером простым способом?
это " OrderInformationScreen "
export default class OrderInformationScreen extends Component {
constructor(props) {
super(props);
const { state } = props.navigation;
this.state = {
title: state.params.data //navprops.params.data.SHORT_TEXT
}
//alert(JSON.stringify((state.params.data.SHORT_TEXT)))
}
render() {
return (
<>
<View
style={{
alignItems: 'flex-start',
justifyContent: 'center',
borderColor: 'blue',
flexDirection: "row",
justifyContent: 'space-evenly'
}}>
<TouchableOpacity onPress={() => console.log("cancel!")}>
<Avatar
size='large'
containerStyle={{ marginTop: 30 }}
activeOpacity={0.2}
rounded
source={require('../assets/down.png')} style={{ height: 80, width: 80 }}
onPress={() => console.log("cancel!")} />
<View >
<Text style={{ fontSize: 25, fontWeight: 'bold', color: 'red' }}>לדחות</Text>
</View>
</TouchableOpacity>
<TouchableOpacity onPress={() => console.log("works!")}>
<Avatar
size='large'
activeOpacity={0.1}
rounded
source={require('../assets/up.png')} style={{ height: 80, width: 80 }}
onPress={() => console.log("Works!")} />
<View>
<Text style={{ fontSize: 25, fontWeight: 'bold', color: 'green', marginHorizontal: 6 }}>לאשר</Text>
</View>
</TouchableOpacity>
</View>
<InfoTable headerInfo={this.state.title}></InfoTable>
</>
);
};
}
это StackNavigator :
const PlacesNavigator = createStackNavigator({
Main: MainScreen,
MyTasks: MyTasksScreen,
Settings: SettingsScreen,
Sync: SyncScreen,
Info: OrderInformationScreen
},
{
defaultNavigationOptions: {
headerStyle: {
animationEnabled: true,
backgroundColor: Platform.OS === 'android' ? Colors.primary : ''
},
headerTintColor: Platform.OS === 'android' ? 'white' : Colors.primary,
}
}
);
export default createAppContainer(PlacesNavigator);
это " SettingsScreen "
import React, { useState, useEffect } from 'react';
import { View, Text } from 'react-native';
import { CheckBox } from 'react-native-elements';
const SettingsScreen = props => {
const [checked1, setChecked1] = useState(null);
const [checked2, setChecked2] = useState(null);
const [checked3, setChecked3] = useState(null);
const [checked5, setChecked5] = useState(null);
const [checked6, setChecked6] = useState(null);
const [checked7, setChecked7] = useState(true);
const [checked8, setChecked8] = useState(null);
const handlePress = title => {
if (title === 'LION') { //6
setChecked6(true), setChecked7(false), setChecked8(false)
} else if (title === 'ZEBRA') {//7
setChecked7(true), setChecked6(false), setChecked8(false)
} else {
setChecked8(true), setChecked7(false), setChecked6(false)
}
}
useEffect(() => {
setChecked7(true)
}, [])
return (
<View>
<CheckBox
iconLeft
checkedColor='red'
title="LIZARD"
checked={checked1}
onPress={() => setChecked1(prev => !prev)}
/>
<CheckBox
iconLeft
checkedColor='red'
title="BIRD"
checked={checked2}
onPress={() => setChecked2(prev => !prev)}
/>
<CheckBox
iconLeft
checkedColor='red'
title="SNAKE"
checked={checked3}
onPress={() => setChecked3(prev => !prev)}
/>
<CheckBox
iconLeft
checkedColor='red'
title="SOUND"
checked={checked5}
onPress={() => setChecked5(prev => !prev)}
/>
<CheckBox
iconLeft
checkedColor='green'
title='LION'
checkedIcon='dot-circle-o'
uncheckedIcon='circle-o'
checked={checked6}
onPress={() => handlePress('LION')}
/>
<CheckBox
iconLeft
checkedColor='green'
title='ZEBRA'
checkedIcon='dot-circle-o'
uncheckedIcon='circle-o'
checked={checked7}
onPress={() => handlePress('ZEBRA')}
/>
<CheckBox
iconLeft
checkedColor='green'
title='BOB'
checkedIcon='dot-circle-o'
uncheckedIcon='circle-o'
checked={checked8}
onPress={() => handlePress('BOB')}
/>
</View>
);
};
SettingsScreen.navigationOptions = {
headerTitle: 'SETTINGS'
};
export default SettingsScreen;
это " InfoTable ":
import React, { Component } from 'react';
import { StyleSheet, View, ScrollView } from 'react-native';
import { Table, Row, Rows } from 'react-native-table-component';
import Swiper from 'react-native-swiper'
export default class InfoTable extends Component {
constructor(props) {
super(props);
this.state = {
tableHead0: [`${this.props.headerInfo.SHORT_TEXT} (${(this.props.headerInfo.ORDERID).replace(/^0+/, '')})`],
tableHead3: ['BANANA'],//THIS I WANT HIDE AND SHOW
tableData3: [
['APPLE', `${this.props.headerInfo.COSTCENTER_TXT} (${(this.props.headerInfo.COSTCENTER)})`],
['MONKEY', `${this.props.headerInfo.LOC_WBS_ELEM_TXT} (${this.props.headerInfo.LOC_WBS_ELEM})`],
['FRIZ', `${this.props.headerInfo.SETTLORDER_TXT} (${this.props.headerInfo.SETTLORDER})`],
]
}
}
componentWillReceiveProps(nextProps) {
if (nextProps.headerInfo != null) {
this.setState({ tableHead0: [nextProps.headerInfo] })
}
alert(JSON.stringify(nextProps))
}
render() {
const state = this.state;
return (
<Swiper style={styles.wrapper} showsButtons={true}>
<ScrollView>
<View style={styles.container}>
<Table borderStyle={{ borderWidth: 2, borderColor: '#d83dff' }}>
<Row data={state.tableHead0} style={styles.head0} textStyle={styles.headText} />
<Row data={state.tableHead3} style={styles.head} textStyle={styles.headText} />
<Rows data={state.tableData3} textStyle={styles.text} />
</Table>
</View>
</ScrollView>
</Swiper>
)
}
}
const styles = StyleSheet.create({
container: { flex: 1, backgroundColor: '#fff' },
head0: { height: 80, backgroundColor: '#54beff' },
head: { height: 40, backgroundColor: '#9febf5' },
headText: { fontWeight: 'bold', fontSize: 20 },
text: { margin: 10 },
});