Skip to content

Commit 223111e

Browse files
committed
Fix Open from Push
• The SDK in the previous commit was not correctly calling onOpened if the user cold-started the app by tapping a push notification • Got rid of duplicate event name string declarations in source and replaced with compiler define statements • Changed the name of setUnauthenticatedEmail: to match the iOS SDK. • The previous commit used a static iOS SDK with the server URL set to the staging server, changed to production
1 parent 9bff391 commit 223111e

File tree

10 files changed

+283
-275
lines changed

10 files changed

+283
-275
lines changed

examples/RNOneSignal/index.android.js

Lines changed: 103 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import {
1616
Dimensions,
1717
KeyboardAvoidingView,
1818
ActivityIndicator,
19-
Platform
19+
Platform,
20+
ScrollView,
21+
Linking
2022
} from 'react-native';
2123

2224
import OneSignal from 'react-native-onesignal';
@@ -40,12 +42,12 @@ export default class RNOneSignal extends Component {
4042
animatingEmailButton : false,
4143
initialOpenFromPush : "Did NOT open from push",
4244
activityWidth : 0,
45+
width: 0,
4346
activityMargin: 0,
4447
buttonColor : Platform.OS == "ios" ? "#ffffff" : "#d45653",
4548
jsonDebugText : ""
4649
});
4750
OneSignal.setLocationShared(true);
48-
this.setState({width: 0});
4951

5052

5153
OneSignal.inFocusDisplaying(2)
@@ -86,8 +88,6 @@ export default class RNOneSignal extends Component {
8688
}
8789

8890
onOpened(openResult) {
89-
this.setState({initialOpenFromPush : "DID open from push"});
90-
9191
console.log('Message: ', openResult.notification.payload.body);
9292
console.log('Data: ', openResult.notification.payload.additionalData);
9393
console.log('isActive: ', openResult.notification.isAppInFocus);
@@ -104,124 +104,126 @@ export default class RNOneSignal extends Component {
104104

105105
render() {
106106
return (
107-
<View style={styles.container}>
108-
<View>
109-
<Image style={styles.imageStyle} source={{uri: imageUri}} />
110-
</View>
111-
<Text style={styles.welcome}>
112-
Welcome to React Native!
113-
</Text>
114-
<Text style={styles.instructions}>
115-
{this.state.initialOpenFromPush}
116-
</Text>
117-
<Text style={styles.instructions}>
118-
To get started, edit index.android.js
119-
</Text>
120-
<Text style={styles.instructions}>
121-
Double tap R on your keyboard to reload,{'\n'}
122-
Shake or press menu button for dev menu
123-
</Text>
124-
<View style={{flexDirection: 'row', overflow: 'hidden'}}>
125-
<View style={styles.buttonContainer}>
126-
<Button style={styles.button}
127-
onPress={() => {
128-
OneSignal.getTags((tags) => {
129-
console.log("Did get tags: ", tags);
130-
131-
this.setState({jsonDebugText : JSON.stringify(tags, null, 2)});
132-
});
133-
}}
134-
title="Get Tags"
135-
color={this.state.buttonColor}
136-
/>
107+
<ScrollView style={styles.scrollView}>
108+
<View style={styles.container}>
109+
<View>
110+
<Image style={styles.imageStyle} source={{uri: imageUri}} />
137111
</View>
138-
<View style={styles.buttonContainer}>
139-
<Button style={styles.button}
140-
onPress={() => {
141-
console.log("Sending tags");
112+
<Text style={styles.welcome}>
113+
Welcome to React Native!
114+
</Text>
115+
<Text style={styles.instructions}>
116+
To get started, edit index.android.js
117+
</Text>
118+
<Text style={styles.instructions}>
119+
Double tap R on your keyboard to reload,{'\n'}
120+
Shake or press menu button for dev menu
121+
</Text>
122+
<View style={{flexDirection: 'row', overflow: 'hidden'}}>
123+
<View style={styles.buttonContainer}>
124+
<Button style={styles.button}
125+
onPress={() => {
126+
OneSignal.getTags((tags) => {
127+
console.log("Did get tags: ", tags);
142128

143-
OneSignal.sendTags({"test_property_1" : "test_value_1", "test_property_2" : "test_value_2"});
144-
}}
145-
title="Send Tags"
146-
color={this.state.buttonColor}
147-
/>
129+
this.setState({jsonDebugText : JSON.stringify(tags, null, 2)});
130+
});
131+
}}
132+
title="Get Tags"
133+
color={this.state.buttonColor}
134+
/>
135+
</View>
136+
<View style={styles.buttonContainer}>
137+
<Button style={styles.button}
138+
onPress={() => {
139+
console.log("Sending tags");
140+
141+
OneSignal.sendTags({"test_property_1" : "test_value_1", "test_property_2" : "test_value_2"});
142+
}}
143+
title="Send Tags"
144+
color={this.state.buttonColor}
145+
/>
146+
</View>
148147
</View>
149-
</View>
150-
<View style={{flexDirection: 'row', overflow: 'hidden'}}>
151-
<View style={styles.buttonContainer}>
152-
<Button style={styles.button}
153-
disabled={!this.state.emailEnabled}
154-
onPress={() => {
155-
this.setState({animatingEmailButton : true, activityWidth : 20, activityMargin: 10})
148+
<View style={{flexDirection: 'row', overflow: 'hidden'}}>
149+
<View style={styles.buttonContainer}>
150+
<Button style={styles.button}
151+
disabled={!this.state.emailEnabled}
152+
onPress={() => {
153+
this.setState({animatingEmailButton : true, activityWidth : 20, activityMargin: 10})
156154

157-
OneSignal.setUnauthenticatedEmail(this.state.email, (error) => {
158-
console.log("Sent email with error: ", error);
155+
OneSignal.setEmail(this.state.email, (error) => {
156+
console.log("Sent email with error: ", error);
159157

160-
this.setState({animatingEmailButton : false, activityWidth : 0, activityMargin: 0})
161-
});
162-
}}
163-
title="Set Test Email"
164-
color={this.state.buttonColor}
158+
this.setState({animatingEmailButton : false, activityWidth : 0, activityMargin: 0})
159+
});
160+
}}
161+
title="Set Test Email"
162+
color={this.state.buttonColor}
163+
/>
164+
</View>
165+
<ActivityIndicator style={{width: this.state.activityWidth, marginLeft : this.state.activityMargin}}
166+
animating={this.state.animatingEmailButton}
165167
/>
168+
<View style={styles.buttonContainer}>
169+
<Button style={styles.button}
170+
onPress={() => {
171+
OneSignal.logoutEmail((error) => {
172+
if (error) {
173+
console.log("Encountered error while attempting to log out: ", error);
174+
} else {
175+
console.log("Logged out successfully");
176+
}
177+
});
178+
}}
179+
title="Logout Email"
180+
color={this.state.buttonColor}
181+
/>
182+
</View>
166183
</View>
167-
<ActivityIndicator style={{width: this.state.activityWidth, marginLeft : this.state.activityMargin}}
168-
animating={this.state.animatingEmailButton}
169-
/>
184+
<KeyboardAvoidingView style={{width: 300, height: 40, borderColor: '#d45653', borderWidth: 2, borderRadius: 5, marginTop: 8}}>
185+
<TextInput style={styles.textInput}
186+
underlineColorAndroid='rgba(0, 0, 0, 0)'
187+
placeholderText='testing'
188+
placeholder='[email protected]'
189+
multiline={false}
190+
keyboardType='email-address'
191+
returnKeyType='done'
192+
textAlign='center'
193+
placeholderTextColor='#d1dde3'
194+
editable={true}
195+
autoCapitalize='none'
196+
keyboardAppearance='dark'
197+
onChangeText={(newText) => {
198+
console.log("New text: ", newText, ", is valid email? ", this.validateEmail(newText));
199+
this.setState({emailEnabled : this.validateEmail(newText), email : newText});
200+
}}
201+
/>
202+
</KeyboardAvoidingView>
170203
<View style={styles.buttonContainer}>
171204
<Button style={styles.button}
172205
onPress={() => {
173-
OneSignal.logoutEmail((error) => {
174-
if (error) {
175-
console.log("Encountered error while attempting to log out: ", error);
176-
} else {
177-
console.log("Logged out successfully");
178-
}
206+
OneSignal.getPermissionSubscriptionState((subscriptionState) => {
207+
this.setState({jsonDebugText : JSON.stringify(subscriptionState, null, 2)});
179208
});
180209
}}
181-
title="Logout Email"
210+
title="Print Subscription State"
182211
color={this.state.buttonColor}
183212
/>
184213
</View>
214+
<Text style={styles.jsonDebugLabelText}>
215+
{this.state.jsonDebugText}
216+
</Text>
185217
</View>
186-
<KeyboardAvoidingView style={{width: 300, height: 40, borderColor: '#d45653', borderWidth: 2, borderRadius: 5, marginTop: 8}}>
187-
<TextInput style={styles.textInput}
188-
underlineColorAndroid='rgba(0, 0, 0, 0)'
189-
placeholderText='testing'
190-
placeholder='[email protected]'
191-
multiline={false}
192-
keyboardType='email-address'
193-
returnKeyType='done'
194-
textAlign='center'
195-
placeholderTextColor='#d1dde3'
196-
editable={true}
197-
autoCapitalize='none'
198-
keyboardAppearance='dark'
199-
onChangeText={(newText) => {
200-
console.log("New text: ", newText, ", is valid email? ", this.validateEmail(newText));
201-
this.setState({emailEnabled : this.validateEmail(newText), email : newText});
202-
}}
203-
/>
204-
</KeyboardAvoidingView>
205-
<View style={styles.buttonContainer}>
206-
<Button style={styles.button}
207-
onPress={() => {
208-
OneSignal.getPermissionSubscriptionState((subscriptionState) => {
209-
this.setState({jsonDebugText : JSON.stringify(subscriptionState, null, 2)});
210-
});
211-
}}
212-
title="Print Subscription State"
213-
color={this.state.buttonColor}
214-
/>
215-
</View>
216-
<Text style={styles.jsonDebugLabelText}>
217-
{this.state.jsonDebugText}
218-
</Text>
219-
</View>
218+
</ScrollView>
220219
);
221220
}
222221
}
223222

224223
const styles = StyleSheet.create({
224+
scrollView: {
225+
backgroundColor: '#F5FCFF'
226+
},
225227
container: {
226228
flex: 1,
227229
flexDirection: 'column',

0 commit comments

Comments
 (0)