@@ -3,16 +3,19 @@ import { useCallback, useEffect, useState } from 'react';
33import {
44 ActivityIndicator ,
55 Alert ,
6+ Platform ,
67 SafeAreaView ,
78 ScrollView ,
89 StyleSheet ,
10+ StatusBar ,
911 Text ,
1012 TouchableOpacity ,
1113 View ,
1214} from 'react-native' ;
1315import { OneSignal } from 'react-native-onesignal' ;
1416
1517const ONESIGNAL_APP_ID = ENV_ONESIGNAL_APP_ID ?. trim ( ) || 'YOUR-ONESIGNAL-APP-ID' ;
18+ const ANDROID_STATUS_BAR_HEIGHT = Platform . OS === 'android' ? ( StatusBar . currentHeight ?? 0 ) : 0 ;
1619
1720const isPlaceholder = ( value : string ) => value . startsWith ( 'YOUR-' ) ;
1821
@@ -55,6 +58,14 @@ export default function App() {
5558 }
5659 } , [ refreshPushState ] ) ;
5760
61+ const testLocationPermissionRequest = useCallback ( ( ) => {
62+ try {
63+ OneSignal . Location . requestPermission ( ) ;
64+ } catch ( error ) {
65+ console . error ( 'OneSignal.Location.requestPermission failed:' , error ) ;
66+ }
67+ } , [ ] ) ;
68+
5869 const sendTestNotification = useCallback ( async ( ) => {
5970 if ( isPlaceholder ( ONESIGNAL_APP_ID ) ) {
6071 Alert . alert (
@@ -106,13 +117,16 @@ export default function App() {
106117 } , [ pushSubscriptionId ] ) ;
107118
108119 return (
109- < SafeAreaView style = { styles . root } >
110- < View style = { styles . header } >
111- < Text style = { styles . headerTitle } > OneSignal</ Text >
112- < Text style = { styles . headerSubtitle } > No-Location Demo</ Text >
113- </ View >
120+ < View style = { styles . root } >
121+ < StatusBar backgroundColor = "#E54B4D" barStyle = "light-content" />
122+ < SafeAreaView style = { styles . headerSafeArea } >
123+ < View style = { styles . header } >
124+ < Text style = { styles . headerTitle } > OneSignal</ Text >
125+ < Text style = { styles . headerSubtitle } > No-Location Demo</ Text >
126+ </ View >
127+ </ SafeAreaView >
114128
115- < ScrollView contentContainerStyle = { styles . content } >
129+ < ScrollView style = { styles . scroll } contentContainerStyle = { styles . content } >
116130 < View style = { styles . section } >
117131 < Text style = { styles . sectionTitle } > App</ Text >
118132 < View style = { styles . card } >
@@ -179,13 +193,23 @@ export default function App() {
179193 < View style = { styles . card } >
180194 < Text style = { styles . body } >
181195 This demo initializes OneSignal and requests notification permission only when you tap
182- the button above. It never calls the location namespace, and native build flags
183- exclude the location module.
196+ the button above. Native build flags exclude the location module. The location test
197+ call may not log a JavaScript error; check Android Logcat or Xcode logs for native
198+ diagnostics.
184199 </ Text >
200+ < View style = { styles . locationButtonWrap } >
201+ < TouchableOpacity
202+ style = { styles . outlinedButton }
203+ onPress = { testLocationPermissionRequest }
204+ activeOpacity = { 0.8 }
205+ >
206+ < Text style = { styles . outlinedButtonText } > TEST LOCATION REQUEST</ Text >
207+ </ TouchableOpacity >
208+ </ View >
185209 </ View >
186210 </ View >
187211 </ ScrollView >
188- </ SafeAreaView >
212+ </ View >
189213 ) ;
190214}
191215
@@ -194,6 +218,14 @@ const styles = StyleSheet.create({
194218 flex : 1 ,
195219 backgroundColor : '#F8F9FA' ,
196220 } ,
221+ headerSafeArea : {
222+ backgroundColor : '#E54B4D' ,
223+ paddingTop : ANDROID_STATUS_BAR_HEIGHT ,
224+ } ,
225+ scroll : {
226+ flex : 1 ,
227+ backgroundColor : '#F8F9FA' ,
228+ } ,
197229 header : {
198230 backgroundColor : '#E54B4D' ,
199231 paddingHorizontal : 16 ,
@@ -269,6 +301,24 @@ const styles = StyleSheet.create({
269301 buttonSpacer : {
270302 height : 8 ,
271303 } ,
304+ locationButtonWrap : {
305+ marginTop : 12 ,
306+ } ,
307+ outlinedButton : {
308+ alignItems : 'center' ,
309+ backgroundColor : 'transparent' ,
310+ borderColor : '#E54B4D' ,
311+ borderRadius : 8 ,
312+ borderWidth : 1 ,
313+ height : 48 ,
314+ justifyContent : 'center' ,
315+ paddingHorizontal : 16 ,
316+ } ,
317+ outlinedButtonText : {
318+ color : '#E54B4D' ,
319+ fontSize : 14 ,
320+ fontWeight : '600' ,
321+ } ,
272322 buttonText : {
273323 color : '#FFFFFF' ,
274324 fontSize : 14 ,
0 commit comments