Skip to content

Commit d43e96b

Browse files
author
Evan Masseau
committed
Variety of styling cleanups and post-rebase stuff
1 parent 2345025 commit d43e96b

File tree

6 files changed

+401
-433
lines changed

6 files changed

+401
-433
lines changed

example/src/App.tsx

Lines changed: 119 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ import { SectionHeader } from './components/SectionHeader';
1919
import { ProfileTextField } from './components/ProfileTextField';
2020
import { ActionButton } from './components/ActionButton';
2121
import { ToggleButtons } from './components/ToggleButtons';
22+
import {
23+
requestLocationPermission,
24+
checkLocationPermissionState,
25+
type LocationPermissionState,
26+
} from './PermissionHelper';
2227

2328
export default function App() {
2429
// Profile state
@@ -29,11 +34,20 @@ export default function App() {
2934
// Feature state
3035
const [pushToken, setPushToken] = useState('');
3136
const [formsRegistered, setFormsRegistered] = useState(false);
37+
const [geofencingRegistered, setGeofencingRegistered] = useState(false);
38+
const [locationPermission, setLocationPermission] =
39+
useState<LocationPermissionState>('none');
40+
41+
// Helper to refresh location permission state
42+
const refreshLocationPermission = async () => {
43+
const state = await checkLocationPermissionState();
44+
setLocationPermission(state);
45+
};
3246

3347
// Initialize SDK and load current state on mount
3448
useEffect(() => {
3549
// Initialize the SDK with public key
36-
Klaviyo.initialize('YOUR_KLAVIYO_PUBLIC_API_KEY');
50+
Klaviyo.initialize('TRJ3wp');
3751

3852
// Load current profile values from SDK
3953
Klaviyo.getEmail((value: string) => {
@@ -52,6 +66,11 @@ export default function App() {
5266
if (value) setPushToken(value);
5367
});
5468

69+
// Check initial location permission state
70+
refreshLocationPermission().then(() => {
71+
console.log('Fetched initial location permission state');
72+
});
73+
5574
// Set up deep linking handler
5675
const handleUrl = (url: string) => {
5776
if (Klaviyo.handleUniversalTrackingLink(url)) {
@@ -172,7 +191,38 @@ export default function App() {
172191
console.log('Unregistered from in-app forms');
173192
};
174193

175-
// Push notifications handler
194+
// Geofencing handlers
195+
const handleRegisterGeofencing = () => {
196+
Klaviyo.registerGeofencing();
197+
setGeofencingRegistered(true);
198+
console.log('Registered for geofencing');
199+
};
200+
201+
const handleUnregisterGeofencing = () => {
202+
Klaviyo.unregisterGeofencing();
203+
setGeofencingRegistered(false);
204+
console.log('Unregistered from geofencing');
205+
};
206+
207+
const handleRequestLocationPermission = async () => {
208+
await requestLocationPermission();
209+
// Refresh permission state after requesting
210+
await refreshLocationPermission();
211+
};
212+
213+
// Push notifications handlers
214+
const handleRequestPushPermission = () => {
215+
// Note: This is a placeholder. In a real app, you would use a push notification
216+
// library like @react-native-firebase/messaging or react-native-push-notification
217+
// to request push permissions. The Klaviyo SDK will handle the token registration
218+
// when you call setPushToken.
219+
Alert.alert(
220+
'Push Notifications',
221+
'Push notification permission requests should be handled by your push notification library (e.g., Firebase). The SDK will automatically register the token when available.',
222+
[{ text: 'OK' }]
223+
);
224+
};
225+
176226
const handleSetBadgeCount = () => {
177227
const randomBadgeCount = Math.floor(Math.random() * 10);
178228
Klaviyo.setBadgeCount(randomBadgeCount);
@@ -211,28 +261,39 @@ export default function App() {
211261
placeholder="+1234567890"
212262
keyboardType="phone-pad"
213263
/>
214-
<ActionButton
215-
title="Set Profile"
216-
onPress={handleSetProfile}
217-
disabled={
218-
!email.trim() && !phoneNumber.trim() && !externalId.trim()
219-
}
220-
/>
221-
<ActionButton
222-
title="Reset Profile"
223-
onPress={handleResetProfile}
224-
destructive
225-
/>
264+
<View style={styles.actionButtonRow}>
265+
<ActionButton
266+
title="Set Profile"
267+
onPress={handleSetProfile}
268+
disabled={
269+
!email.trim() && !phoneNumber.trim() && !externalId.trim()
270+
}
271+
inRow
272+
/>
273+
<ActionButton
274+
title="Reset Profile"
275+
onPress={handleResetProfile}
276+
destructive
277+
inRow
278+
/>
279+
</View>
226280
</View>
227281

228282
{/* Events Section */}
229283
<View style={styles.section}>
230284
<SectionHeader title="Events" />
231-
<ActionButton
232-
title="Create Test Event"
233-
onPress={handleCreateTestEvent}
234-
/>
235-
<ActionButton title="Viewed Product" onPress={handleViewedProduct} />
285+
<View style={styles.actionButtonRow}>
286+
<ActionButton
287+
title="Test Event"
288+
onPress={handleCreateTestEvent}
289+
inRow
290+
/>
291+
<ActionButton
292+
title="Viewed Product"
293+
onPress={handleViewedProduct}
294+
inRow
295+
/>
296+
</View>
236297
</View>
237298

238299
{/* In-App Forms Section */}
@@ -244,12 +305,51 @@ export default function App() {
244305
isLeftActive={formsRegistered}
245306
onLeftPress={handleRegisterForms}
246307
onRightPress={handleUnregisterForms}
308+
leftDisabled={formsRegistered}
309+
rightDisabled={!formsRegistered}
310+
/>
311+
</View>
312+
313+
{/* Geofencing & Location Section */}
314+
<View style={styles.section}>
315+
<SectionHeader title="Geofencing & Location" />
316+
{locationPermission === 'none' && (
317+
<ActionButton
318+
title="Request Location Permission"
319+
onPress={handleRequestLocationPermission}
320+
/>
321+
)}
322+
{locationPermission === 'inUse' && (
323+
<ActionButton
324+
title="Request Background Permission"
325+
onPress={handleRequestLocationPermission}
326+
/>
327+
)}
328+
{locationPermission === 'background' && (
329+
<View style={styles.permissionGrantedContainer}>
330+
<Text style={styles.permissionGrantedText}>
331+
Background Permission Granted
332+
</Text>
333+
</View>
334+
)}
335+
<ToggleButtons
336+
leftLabel="Register"
337+
rightLabel="Unregister"
338+
isLeftActive={geofencingRegistered}
339+
onLeftPress={handleRegisterGeofencing}
340+
onRightPress={handleUnregisterGeofencing}
341+
leftDisabled={geofencingRegistered}
342+
rightDisabled={!geofencingRegistered}
247343
/>
248344
</View>
249345

250346
{/* Push Notifications Section */}
251347
<View style={styles.section}>
252348
<SectionHeader title="Push Notifications" />
349+
<ActionButton
350+
title="Request Push Permission"
351+
onPress={handleRequestPushPermission}
352+
/>
253353
<View style={styles.pushTokenContainer}>
254354
<Text style={styles.pushTokenLabel}>Push Token</Text>
255355
<Text

0 commit comments

Comments
 (0)