Working iOS example
This commit is contained in:
43
example/src/Navigation.js
Normal file
43
example/src/Navigation.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
StyleSheet,
|
||||
View,
|
||||
} from 'react-native';
|
||||
import { Navigator } from 'react-native-deprecated-custom-components';
|
||||
|
||||
import Page1 from './Page1';
|
||||
import Page2 from './Page2';
|
||||
import Page404 from './Page2';
|
||||
|
||||
const INITIAL_ROUTE = { id: 'page1' };
|
||||
|
||||
class Navigation extends React.PureComponent {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View style={styles.main}>
|
||||
<Navigator
|
||||
ref={ (component) => global.appNavigator = component }
|
||||
initialRoute={ INITIAL_ROUTE }
|
||||
renderScene={ this.renderScene }
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
renderScene(route) {
|
||||
switch (route.id) {
|
||||
case 'page1': return <Page1/>;
|
||||
case 'page2': return <Page2/>;
|
||||
default: return <Page404/>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
main: {
|
||||
flex: 1,
|
||||
},
|
||||
});
|
||||
|
||||
export default Navigation;
|
||||
46
example/src/Page1.js
Normal file
46
example/src/Page1.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
Alert,
|
||||
StyleSheet,
|
||||
TouchableOpacity,
|
||||
Text,
|
||||
View,
|
||||
} from 'react-native';
|
||||
|
||||
import AppMetrica from './appmetrica';
|
||||
|
||||
class Page1 extends React.PureComponent {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View style={styles.main}>
|
||||
<Text>page1</Text>
|
||||
<TouchableOpacity onPress={ this.handlePress }>
|
||||
<Text>go to page2</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity onPress={ this.reportEventToAppMetrica }>
|
||||
<Text>report event to AppMetrica</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
handlePress() {
|
||||
appNavigator.push({ id: 'page2' });
|
||||
}
|
||||
|
||||
reportEventToAppMetrica() {
|
||||
AppMetrica.reportEvent('event from page1');
|
||||
Alert.alert('OK!');
|
||||
}
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
main: {
|
||||
flex: 1,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
});
|
||||
|
||||
export default Page1;
|
||||
35
example/src/Page2.js
Normal file
35
example/src/Page2.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
StyleSheet,
|
||||
TouchableOpacity,
|
||||
Text,
|
||||
View,
|
||||
} from 'react-native';
|
||||
|
||||
class Page2 extends React.PureComponent {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View style={styles.main}>
|
||||
<Text>page2</Text>
|
||||
<TouchableOpacity onPress={ this.handlePress }>
|
||||
<Text>go back</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
handlePress() {
|
||||
appNavigator.push({ id: 'page2' });
|
||||
}
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
main: {
|
||||
flex: 1,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
});
|
||||
|
||||
export default Page2;
|
||||
27
example/src/Page404.js
Normal file
27
example/src/Page404.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
StyleSheet,
|
||||
Text,
|
||||
View,
|
||||
} from 'react-native';
|
||||
|
||||
class Page2 extends React.PureComponent {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View style={styles.main}>
|
||||
<Text>Unknown page</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
main: {
|
||||
flex: 1,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
});
|
||||
|
||||
export default Page2;
|
||||
5
example/src/appmetrica.js
Normal file
5
example/src/appmetrica.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import AppMetrica from 'react-native-appmetrica';
|
||||
|
||||
AppMetrica.activateWithApiKey('2dee16d2-1143-4cd3-a904-39ce10ac2755');
|
||||
|
||||
export default AppMetrica;
|
||||
Reference in New Issue
Block a user