Skip to content

Commit 774b7be

Browse files
author
Evan Masseau
committed
Add back the current geofences button, and some style DRYness
1 parent 0a359f8 commit 774b7be

File tree

4 files changed

+64
-50
lines changed

4 files changed

+64
-50
lines changed

example/src/App.tsx

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -206,34 +206,40 @@ export default function App() {
206206

207207
const handleGetCurrentGeofences = () => {
208208
// Note: this @internal method is intended only for demonstration and debugging purposes
209-
Klaviyo.getCurrentGeofences((result: { geofences: Array<{
210-
identifier: string;
211-
latitude: number;
212-
longitude: number;
213-
radius: number;
214-
}> }) => {
215-
const { geofences } = result;
216-
console.log('Current geofences:', JSON.stringify(geofences, null, 2));
217-
218-
if (geofences.length === 0) {
219-
Alert.alert(
220-
'Current Geofences',
221-
'No geofences are currently being monitored.',
222-
[{ text: 'OK' }]
223-
);
224-
} else {
225-
const geofencesList = geofences
226-
.map(
227-
(g, index) =>
228-
`${index + 1}. ${g.identifier}\n Center: (${g.latitude.toFixed(6)}, ${g.longitude.toFixed(6)})\n Radius: ${g.radius.toFixed(2)}m`
229-
)
230-
.join('\n\n');
231-
232-
Alert.alert(`Current Geofences (${geofences.length})`, geofencesList, [
233-
{ text: 'OK' },
234-
]);
209+
Klaviyo.getCurrentGeofences(
210+
(result: {
211+
geofences: Array<{
212+
identifier: string;
213+
latitude: number;
214+
longitude: number;
215+
radius: number;
216+
}>;
217+
}) => {
218+
const { geofences } = result;
219+
console.log('Current geofences:', JSON.stringify(geofences, null, 2));
220+
221+
if (geofences.length === 0) {
222+
Alert.alert(
223+
'Current Geofences',
224+
'No geofences are currently being monitored.',
225+
[{ text: 'OK' }]
226+
);
227+
} else {
228+
const geofencesList = geofences
229+
.map(
230+
(g, index) =>
231+
`${index + 1}. ${g.identifier}\n Center: (${g.latitude.toFixed(6)}, ${g.longitude.toFixed(6)})\n Radius: ${g.radius.toFixed(2)}m`
232+
)
233+
.join('\n\n');
234+
235+
Alert.alert(
236+
`Current Geofences (${geofences.length})`,
237+
geofencesList,
238+
[{ text: 'OK' }]
239+
);
240+
}
235241
}
236-
});
242+
);
237243
};
238244

239245
const handleRequestLocationPermission = async () => {
@@ -377,6 +383,7 @@ export default function App() {
377383
<ActionButton
378384
title="Get Current Geofences"
379385
onPress={handleGetCurrentGeofences}
386+
withTopSpacing
380387
/>
381388
)}
382389
</View>

example/src/Styles.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
import { StyleSheet, Platform } from 'react-native';
22
import { colors, spacing, typography, borderRadius } from './theme';
33

4+
// Shared base styles for DRY
5+
const buttonBase = {
6+
paddingVertical: spacing.md - 2, // 14px
7+
paddingHorizontal: spacing.md,
8+
borderRadius: borderRadius.sm,
9+
alignItems: 'center' as const,
10+
justifyContent: 'center' as const,
11+
minHeight: 48,
12+
borderWidth: 1,
13+
borderColor: colors.primary,
14+
backgroundColor: colors.cardBackground,
15+
};
16+
17+
const rowContainerBase = {
18+
flexDirection: 'row' as const,
19+
marginHorizontal: -spacing.xs / 2, // Negative margin for spacing trick
20+
};
21+
422
export const styles = StyleSheet.create({
523
// Container styles
624
container: {
@@ -89,21 +107,12 @@ export const styles = StyleSheet.create({
89107

90108
// Action button styles
91109
actionButtonRow: {
92-
flexDirection: 'row',
93-
marginHorizontal: -spacing.xs / 2, // Negative margin for spacing
110+
...rowContainerBase,
94111
marginBottom: spacing.sm,
95112
},
96113
actionButton: {
97-
backgroundColor: colors.cardBackground,
98-
paddingVertical: spacing.md - 2, // 14px
99-
paddingHorizontal: spacing.md,
100-
borderRadius: borderRadius.sm,
101-
alignItems: 'center',
102-
justifyContent: 'center',
114+
...buttonBase,
103115
marginBottom: spacing.sm,
104-
minHeight: 48, // Larger touch target for standalone buttons
105-
borderWidth: 1,
106-
borderColor: colors.primary,
107116
},
108117
actionButtonInRow: {
109118
flex: 1,
@@ -127,27 +136,21 @@ export const styles = StyleSheet.create({
127136
actionButtonTextDisabled: {
128137
color: colors.secondaryText,
129138
},
139+
actionButtonWithTopSpacing: {
140+
marginTop: spacing.sm,
141+
},
130142

131143
// Toggle button styles
132144
toggleContainer: {
133-
flexDirection: 'row',
134-
marginHorizontal: -spacing.xs / 2, // Negative margin for spacing trick
145+
...rowContainerBase,
135146
},
136147
toggleButton: {
148+
...buttonBase,
137149
flex: 1,
138-
paddingVertical: spacing.md - 2, // 14px
139-
paddingHorizontal: spacing.md,
140-
borderRadius: borderRadius.sm,
141-
alignItems: 'center',
142-
justifyContent: 'center',
143-
borderWidth: 1,
144-
borderColor: colors.primary,
145-
backgroundColor: colors.cardBackground,
146-
minHeight: 48,
147150
marginHorizontal: spacing.xs / 2, // Half spacing on each side = full spacing between buttons
148151
},
149152
toggleButtonActive: {
150-
backgroundColor: '#E8F4FF', // Light blue tint for active state
153+
backgroundColor: colors.activeButtonTint,
151154
},
152155
toggleButtonText: {
153156
...typography.button,

example/src/components/ActionButton.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface ActionButtonProps {
88
disabled?: boolean;
99
destructive?: boolean;
1010
inRow?: boolean;
11+
withTopSpacing?: boolean;
1112
}
1213

1314
/**
@@ -19,6 +20,7 @@ export const ActionButton: React.FC<ActionButtonProps> = ({
1920
disabled = false,
2021
destructive = false,
2122
inRow = false,
23+
withTopSpacing = false,
2224
}) => {
2325
return (
2426
<TouchableOpacity
@@ -27,6 +29,7 @@ export const ActionButton: React.FC<ActionButtonProps> = ({
2729
inRow && styles.actionButtonInRow,
2830
destructive && styles.actionButtonDestructive,
2931
disabled && styles.actionButtonDisabled,
32+
withTopSpacing && styles.actionButtonWithTopSpacing,
3033
]}
3134
onPress={onPress}
3235
disabled={disabled}

example/src/theme.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const colors = {
2727
// Button states
2828
buttonText: '#FFFFFF', // White text on buttons
2929
buttonBorder: '#007AFF', // Border for outlined buttons
30+
activeButtonTint: '#E8F4FF', // Light blue tint for active toggle buttons
3031
};
3132

3233
export const spacing = {

0 commit comments

Comments
 (0)