Created
April 13, 2020 09:51
-
-
Save a-h/30d07f2d96fc1eb492e25d84a5b07395 to your computer and use it in GitHub Desktop.
Firebase Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useEffect} from 'react'; | |
import {AppState, Linking} from 'react-native'; | |
import {Provider as PaperProvider} from 'react-native-paper'; | |
import { | |
SafeAreaView, | |
StyleSheet, | |
ScrollView, | |
View, | |
Text, | |
StatusBar, | |
} from 'react-native'; | |
import {Button} from 'react-native-paper'; | |
import 'react-native-gesture-handler'; | |
import analytics from '@react-native-firebase/analytics'; | |
import dynamicLinks from '@react-native-firebase/dynamic-links'; | |
analytics() | |
.logEvent('application_started', { | |
id: '123456789', | |
color: 'red', | |
via: 'ProductCatalog', | |
}) | |
.then(() => console.log('firebase test app loaded complete')) | |
.catch(err => console.error(err)); | |
dynamicLinks() | |
.buildLink({ | |
link: 'https://example.com/test', | |
domainUriPrefix: 'https://xyz.page.link', | |
analytics: { | |
campaign: 'banner', | |
}, | |
}) | |
.then(link => console.log(link)) | |
.catch(err => console.error(err)); | |
export default (App = () => { | |
useEffect(() => { | |
try { | |
AppState.addEventListener('change', async state => { | |
const initialLink = await dynamicLinks().getInitialLink(); | |
if (initialLink) { | |
console.log( | |
'dynamicLinks().getInitialLink(): ' + JSON.stringify(initialLink), | |
); | |
} else { | |
console.log('Not opened by using a link.'); | |
} | |
console.log('AppState changed to', state); | |
}); | |
} catch (err) { | |
console.error('dynamicLinks().getInitialLink():', err); | |
} | |
try { | |
dynamicLinks().onLink(dispatchUrl => | |
console.log('dynamicLinks().onLink():', dispatchUrl), | |
); | |
} catch (err) { | |
console.error('dynamicLinks().onLink():', err); | |
} | |
try { | |
Linking.addEventListener('url', url => | |
console.log('Linking.addEventListener:', JSON.stringify(url)), | |
); | |
} catch (err) { | |
console.error('Linking.addEventListener: ', err); | |
} | |
try { | |
const initialUrl = Linking.getInitialURL(); | |
if (initialUrl) { | |
console.log('Linking.getInitialURL(): ', JSON.stringify(initialUrl)); | |
} | |
} catch (err) { | |
console.error('Linking.getInitialURL(): ', err); | |
} | |
}, []); | |
return ( | |
<PaperProvider> | |
<StatusBar barStyle="dark-content" /> | |
<SafeAreaView> | |
<ScrollView contentInsetAdjustmentBehavior="automatic"> | |
{global.HermesInternal == null ? null : ( | |
<View style={styles.engine}> | |
<Text style={styles.footer}>Engine: Hermes</Text> | |
</View> | |
)} | |
<View style={styles.body}> | |
<View style={styles.sectionContainer}> | |
<Text style={styles.sectionTitle}>thinkmoney Firebase Test</Text> | |
<Text style={styles.sectionDescription} /> | |
</View> | |
<View style={{padding: 10}}> | |
<Button | |
icon="cursor-default-click" | |
mode="contained" | |
onPress={async () => { | |
await analytics().logEvent('application_started', { | |
id: 'new_event_id', | |
key: 123, | |
}); | |
console.log('pushed application_started event OK'); | |
}}> | |
Send 'application_started' | |
</Button> | |
<View style="{ marginTop: 10 }"> | |
<Text> </Text> | |
</View> | |
<Button | |
icon="cursor-default-click" | |
mode="contained" | |
onPress={async () => { | |
await analytics().logEvent('product_view', { | |
id: 'new_event_id', | |
key: 123, | |
}); | |
console.log('pushed product_view event OK'); | |
}}> | |
Send 'product_view' | |
</Button> | |
</View> | |
</View> | |
</ScrollView> | |
</SafeAreaView> | |
</PaperProvider> | |
); | |
}); | |
const styles = StyleSheet.create({ | |
engine: { | |
position: 'absolute', | |
right: 0, | |
}, | |
body: { | |
backgroundColor: '#ffffff', | |
}, | |
sectionContainer: { | |
marginTop: 32, | |
paddingHorizontal: 24, | |
}, | |
sectionTitle: { | |
fontSize: 24, | |
fontWeight: '600', | |
color: '#000000', | |
}, | |
sectionDescription: { | |
marginTop: 8, | |
fontSize: 18, | |
fontWeight: '400', | |
}, | |
highlight: { | |
fontWeight: '700', | |
}, | |
footer: { | |
fontSize: 12, | |
fontWeight: '600', | |
padding: 4, | |
paddingRight: 12, | |
textAlign: 'right', | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment