1- import React from 'react'
2- import { NavigationContainer } from '@react-navigation/native'
3- import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
4- import Icon from 'react-native-vector-icons/Ionicons'
5- import HomeTab from './HomeTab'
6- import SettingsTab from './SettingsTab'
7- import { coffees } from './Data'
8-
9- // Step 1:
10- // Import the Iterable and IterableConfig class.
1+ import React from 'react' ;
2+ import { NavigationContainer } from '@react-navigation/native' ;
3+ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs' ;
4+ import Icon from 'react-native-vector-icons/Ionicons' ;
5+ import HomeTab from './HomeTab' ;
6+ import SettingsTab from './SettingsTab' ;
7+ import { coffees } from './Data' ;
8+
9+ // Step 1:
10+ // Import the Iterable and IterableConfig class.
1111// Refer to "Installing Iterable's React Native SDK" of the developer guide.
1212// (https://support.iterable.com/hc/en-us/articles/360045714132-Installing-Iterable-s-React-Native-SDK-#step-5-import-iterable-sdk-classes-wherever-needed)
1313
14- import { Iterable , IterableConfig } from '@iterable/react-native-sdk'
14+ import { Iterable , IterableConfig , } from '@iterable/react-native-sdk' ;
1515
16- // Step 2:
16+ // Step 2:
1717// Create a Config.js and add your apiKey as "iterableAPIKey".
18- // Refer to "Creating API Keys" under "API Keys" of the developer guide
18+ // Refer to "Creating API Keys" under "API Keys" of the developer guide
1919// to create an API key for your Iterable project.
2020// (https://support.iterable.com/hc/en-us/articles/360043464871#creating-api-keys)
2121
22- import { iterableAPIKey } from './Config'
22+ import { iterableAPIKey } from './Config' ;
2323
2424export default class App extends React . Component {
25- constructor ( props ) {
26- super ( props )
27-
28- this . homeTabRef = React . createRef ( )
29-
30- // Step 3: Initialize the React Native SDK here.
31- // Create an IterableConfig object with various properties set.
32- // The config object is used to customize various features of the SDK such as the URL handler and custom action handler.
33- // If a config object is not defined, the React Native SDK defaults to the default configuration.
34-
35- // The IterableConfig.js file is linked to the documentation.
36- // Refer to Step 6 of "Installing Iterable's React Native SDK" of the developer guide.
37- // (https://support.iterable.com/hc/en-us/articles/360045714132-Installing-Iterable-s-React-Native-SDK-#step-6-initialize-iterable-s-react-native-sdk)
38-
39- // Below is a sample implementation of the config object where we set the urlHAndler and inAppDisplayInterval
40-
41- const config = new IterableConfig ( )
42-
43- // inAppDisplayInterval sets the number of seconds to wait between displaying multiple in-app messages in sequence
44- config . inAppDisplayInterval = 1.0
45-
46- // urlHandler is set up here to handle deep link URLs and in-app message buttons and link URLs
47- config . urlHandler = this . urlHandler
25+ constructor ( props ) {
26+ super ( props ) ;
27+
28+ this . homeTabRef = React . createRef ( ) ;
29+
30+ // Step 3: Initialize the React Native SDK here.
31+ // Create an IterableConfig object with various properties set.
32+ // The config object is used to customize various features of the SDK such as the URL handler and custom action handler.
33+ // If a config object is not defined, the React Native SDK defaults to the default configuration.
34+
35+ // The IterableConfig.js file is linked to the documentation.
36+ // Refer to Step 6 of "Installing Iterable's React Native SDK" of the developer guide.
37+ // (https://support.iterable.com/hc/en-us/articles/360045714132-Installing-Iterable-s-React-Native-SDK-#step-6-initialize-iterable-s-react-native-sdk)
38+
39+ // Below is a sample implementation of the config object where we set the urlHAndler and inAppDisplayInterval
40+
41+ const config = new IterableConfig ( ) ;
42+
43+ // inAppDisplayInterval sets the number of seconds to wait between displaying multiple in-app messages in sequence
44+ config . inAppDisplayInterval = 1.0 ;
45+
46+ // urlHandler is set up here to handle deep link URLs and in-app message buttons and link URLs
47+ config . urlHandler = this . urlHandler ;
48+
49+ // Initialize by calling the Iterable.initialize method passing in your API key and the optional config object.
50+ Iterable . initialize ( iterableAPIKey , config ) ;
51+ }
52+ render ( ) {
53+ const Tab = createBottomTabNavigator ( ) ;
54+ return ( React . createElement ( NavigationContainer , null ,
55+ React . createElement ( Tab . Navigator , { screenOptions : ( { route } ) => ( {
56+ tabBarIcon : ( { focused, color, size } ) => {
57+ if ( route . name == 'Home' ) {
58+ return React . createElement ( Icon , { name : "ios-home" , size : size , color : color } ) ;
59+ }
60+ else {
61+ return React . createElement ( Icon , { name : "ios-settings" , size : size , color : color } ) ;
62+ }
63+ } ,
64+ } ) , tabBarOptions : {
65+ activeTintColor : 'tomato' ,
66+ inactiveTintColor : 'gray' ,
67+ showIcon : true ,
68+ } } ,
69+ React . createElement ( Tab . Screen , { name : "Home" , options : { title : "Coffees" } } , props => React . createElement ( HomeTab , Object . assign ( { ref : this . homeTabRef } , props ) ) ) ,
70+ React . createElement ( Tab . Screen , { name : "Settings" , component : SettingsTab } ) ) ) ) ;
71+ }
4872
49- // Initialize by calling the Iterable.initialize method passing in your API key and the optional config object.
50- Iterable . initialize ( iterableAPIKey , config )
51- }
73+ navigate ( coffee ) {
74+ if ( this . homeTabRef && this . homeTabRef . current ) {
75+ this . homeTabRef . current . navigate ( coffee ) ;
76+ }
77+ }
5278
53- render ( ) {
54- const Tab = createBottomTabNavigator ( )
55- return ( React . createElement ( NavigationContainer , null ,
56- React . createElement ( Tab . Navigator , {
57- screenOptions : ( { route } ) => ( {
58- tabBarIcon : ( { focused, color, size } ) => {
59- if ( route . name === 'Home' ) {
60- return React . createElement ( Icon , { name : 'ios-home' , size, color } )
79+ // urlHandler is defined here
80+ urlHandler = ( url , context ) => {
81+ console . log ( `urlHandler, url: ${ url } ` ) ;
82+ let match = url . match ( / c o f f e e \/ ( [ ^ \/ ] + ) / i) ;
83+ if ( match && match . length > 1 ) {
84+ const id = match [ 1 ] ;
85+ const foundCoffee = coffees . find ( coffee => coffee . id == id ) ;
86+ if ( foundCoffee ) {
87+ this . navigate ( foundCoffee ) ;
6188 } else {
62- return React . createElement ( Icon , { name : 'ios-settings' , size , color } )
89+ console . log ( `could not find coffee with id: ${ id } ` ) ;
6390 }
64- }
65- } ) ,
66- tabBarOptions : {
67- activeTintColor : 'tomato' ,
68- inactiveTintColor : 'gray' ,
69- showIcon : true
91+ return true ;
92+ } else {
93+ console . log ( "opening external url" ) ;
94+ return false ;
7095 }
71- } ,
72- React . createElement ( Tab . Screen , { name : 'Home' , options : { title : 'Coffees' } } , props => React . createElement ( HomeTab , Object . assign ( { ref : this . homeTabRef } , props ) ) ) ,
73- React . createElement ( Tab . Screen , { name : 'Settings' , component : SettingsTab } ) ) ) )
74- }
75-
76- navigate ( coffee ) {
77- if ( this . homeTabRef && this . homeTabRef . current ) {
78- this . homeTabRef . current . navigate ( coffee )
79- }
80- }
81-
82- // urlHandler is defined here
83- urlHandler = ( url , context ) => {
84- console . log ( `urlHandler, url: ${ url } ` )
85- const match = url . match ( / c o f f e e \/ ( [ ^ ] + ) / i)
86- if ( match && match . length > 1 ) {
87- const id = match [ 1 ]
88- const foundCoffee = coffees . find ( coffee => coffee . id === id )
89- if ( foundCoffee ) {
90- this . navigate ( foundCoffee )
91- } else {
92- console . log ( `could not find coffee with id: ${ id } ` )
93- }
94- return true
95- } else {
96- console . log ( 'opening external url' )
97- return false
9896 }
99- }
100- }
97+ }
0 commit comments