static navigationOptions = ({ navigation }) => {
const { params } = navigation.state;
return {
title: params ? params.otherParam : 'A Nested Details Screen',
}
};
class DetailsScreen extends React.Component {
static navigationOptions = ({ navigation }) => {
const { params } = navigation.state;
return {
title: params ? params.otherParam : 'A Nested Details Screen',
}
};
render() {
/* 2. Read the params from the navigation state */
const { params } = this.props.navigation.state;
const itemId = params ? params.itemId : null;
const otherParam = params ? params.otherParam : null;
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Details Screen</Text>
<Text>itemId: {JSON.stringify(itemId)}</Text>
<Text>otherParam: {JSON.stringify(otherParam)}</Text>
<Button
title="Update the title"
onPress={() => this.props.navigation.setParams({otherParam: 'Updated!'})}
/>
</View>
);
}
}
const MainScreen = ({ navigation, image }) => {
//Эта функция принимает изображение ,преобразовывает его в base64 и отправляет на сервер ,а результат записывает в state
const getCategory = async () => {
let string = ''
const send = new FormData();
ImageResizer.createResizedImage(image, 600, 600, 'JPEG', 100)
.then((res) => RNFS.readFile(res.uri, 'base64'))
.then((res) => {
string = 'data:image/jpeg:base64,'.concat(res);
send.append('link', string);
return axios.post('https://api', send)
})
.then(res => {
const array = Object.values(res.data)
categoryList(array);
}).then(()=>navigation.navigate('Category',{image:string}))
}
return (
<View style={styles.container}>
<PhotoPicker getCategory={getCategory} />
</View>
)
}
MainScreen.navigationOptions = ({ navigation }) => {
const image = this.props.navigation.getParam('image', '');
return {
headerTitle: 'Фильтр поиска',
headerRight: () => (
<TouchableOpacity activeOpacity={0.7} onPress={() => console.log(image !== undefined ? image : <Text>image</Text>)} >
<HeaderButtons>
<Button
color='#BA5C06'
size={10}
title="Очистить" />
</HeaderButtons>
</TouchableOpacity>
)
}
}
NavigationActions.navigate({
'Profile',
{test:true}
});
const name = this.props.navigation.getParam('test', false); //default value false if test undefined or null
import React from 'react';
class ShowWindowDimensions extends React.Component {
state = { width: 0, height: 0 };
render() {
return <span>Window size: {this.state.width} x {this.state.height}</span>;
}
updateDimensions = () => {
this.setState({ width: window.innerWidth, height: window.innerHeight });
};
componentDidMount() {
window.addEventListener('resize', this.updateDimensions);
}
componentWillUnmount() {
window.removeEventListener('resize', this.updateDimensions);
}
}