Skip to content

Commit edf4685

Browse files
committed
chore(demo): add clear all notifications button
1 parent 0630392 commit edf4685

File tree

13 files changed

+59
-8
lines changed

13 files changed

+59
-8
lines changed

examples/build.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# OneSignal Expo Sample App - Build Guide
22

3-
This document covers Expo-specific setup and adaptations. For the full feature spec, UI sections, architecture, and shared implementation details, see the [generic build guide](https://github.com/OneSignal/sdk-shared/blob/main/demo/build.md).
3+
This document extends the shared build guide with Expo-specific details.
4+
5+
**Read the shared guide first:**
6+
https://raw.githubusercontent.com/OneSignal/sdk-shared/refs/heads/main/demo/build.md
7+
8+
Replace `{{PLATFORM}}` with `Expo` everywhere in that guide. Everything below either overrides or supplements sections from the shared guide.
49

510
---
611

examples/demo/src/components/modals/CustomNotificationModal.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
KeyboardAvoidingView,
1010
Platform,
1111
} from 'react-native';
12-
import { AppColors, AppDialogStyles } from '../../theme';
12+
import { AppColors, AppDialogStyles, AppInputProps } from '../../theme';
1313

1414
interface Props {
1515
visible: boolean;
@@ -61,6 +61,7 @@ export default function CustomNotificationModal({
6161
value={title}
6262
onChangeText={setTitle}
6363
autoFocus
64+
{...AppInputProps}
6465
testID="custom_notification_title_input"
6566
/>
6667
<TextInput
@@ -69,6 +70,7 @@ export default function CustomNotificationModal({
6970
placeholderTextColor={AppColors.osGrey600}
7071
value={body}
7172
onChangeText={setBody}
73+
{...AppInputProps}
7274
testID="custom_notification_body_input"
7375
/>
7476
<View style={AppDialogStyles.actions}>

examples/demo/src/components/modals/LoginModal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
TouchableOpacity,
1010
View,
1111
} from 'react-native';
12-
import { AppColors, AppDialogStyles } from '../../theme';
12+
import { AppColors, AppDialogStyles, AppInputProps } from '../../theme';
1313

1414
interface Props {
1515
visible: boolean;
@@ -55,6 +55,7 @@ export default function LoginModal({ visible, onConfirm, onClose }: Props) {
5555
value={userId}
5656
onChangeText={setUserId}
5757
autoFocus
58+
{...AppInputProps}
5859
testID="login_user_id_input"
5960
/>
6061
<View style={AppDialogStyles.actions}>

examples/demo/src/components/modals/MultiPairInputModal.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
Platform,
1212
} from 'react-native';
1313
import { MaterialIcons as Icon } from '@expo/vector-icons';
14-
import { AppColors, AppDialogStyles } from '../../theme';
14+
import { AppColors, AppDialogStyles, AppInputProps } from '../../theme';
1515

1616
interface Row {
1717
id: number;
@@ -107,6 +107,7 @@ export default function MultiPairInputModal({
107107
value={row.key}
108108
onChangeText={(t) => updateRow(row.id, 'key', t)}
109109
autoFocus={idx === 0}
110+
{...AppInputProps}
110111
testID={idx === 0 ? 'multi_pair_key_0' : undefined}
111112
/>
112113
<TextInput
@@ -115,6 +116,7 @@ export default function MultiPairInputModal({
115116
placeholderTextColor={AppColors.osGrey600}
116117
value={row.value}
117118
onChangeText={(t) => updateRow(row.id, 'value', t)}
119+
{...AppInputProps}
118120
testID={idx === 0 ? 'multi_pair_value_0' : undefined}
119121
/>
120122
{rows.length > 1 && (

examples/demo/src/components/modals/OutcomeModal.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import {
99
KeyboardAvoidingView,
1010
Platform,
1111
} from 'react-native';
12-
import { AppColors, AppTextStyles, AppDialogStyles } from '../../theme';
12+
import {
13+
AppColors,
14+
AppTextStyles,
15+
AppDialogStyles,
16+
AppInputProps,
17+
} from '../../theme';
1318

1419
type OutcomeType = 'normal' | 'unique' | 'withValue';
1520

@@ -103,6 +108,7 @@ export default function OutcomeModal({
103108
value={name}
104109
onChangeText={setName}
105110
autoFocus
111+
{...AppInputProps}
106112
testID="outcome_name_input"
107113
/>
108114
{outcomeType === 'withValue' && (
@@ -113,6 +119,7 @@ export default function OutcomeModal({
113119
value={value}
114120
onChangeText={setValue}
115121
keyboardType="numeric"
122+
{...AppInputProps}
116123
testID="outcome_value_input"
117124
/>
118125
)}

examples/demo/src/components/modals/PairInputModal.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
KeyboardAvoidingView,
1010
Platform,
1111
} from 'react-native';
12-
import { AppColors, AppDialogStyles } from '../../theme';
12+
import { AppColors, AppDialogStyles, AppInputProps } from '../../theme';
1313

1414
interface Props {
1515
visible: boolean;
@@ -78,6 +78,7 @@ export default function PairInputModal({
7878
value={keyValue}
7979
onChangeText={setKeyValue}
8080
autoFocus
81+
{...AppInputProps}
8182
testID={keyTestID}
8283
/>
8384
<TextInput
@@ -90,6 +91,7 @@ export default function PairInputModal({
9091
placeholderTextColor={AppColors.osGrey600}
9192
value={val}
9293
onChangeText={setVal}
94+
{...AppInputProps}
9395
testID={valueTestID}
9496
/>
9597
</View>

examples/demo/src/components/modals/SingleInputModal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
KeyboardAvoidingView,
1010
Platform,
1111
} from 'react-native';
12-
import { AppColors, AppDialogStyles } from '../../theme';
12+
import { AppColors, AppDialogStyles, AppInputProps } from '../../theme';
1313

1414
interface Props {
1515
visible: boolean;
@@ -67,6 +67,7 @@ export default function SingleInputModal({
6767
onChangeText={setValue}
6868
keyboardType={keyboardType}
6969
autoFocus
70+
{...AppInputProps}
7071
testID={testID}
7172
/>
7273
<View style={AppDialogStyles.actions}>

examples/demo/src/components/modals/TrackEventModal.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
AppTextStyles,
1515
AppSpacing,
1616
AppDialogStyles,
17+
AppInputProps,
1718
} from '../../theme';
1819

1920
interface Props {
@@ -103,6 +104,7 @@ export default function TrackEventModal({
103104
value={name}
104105
onChangeText={setName}
105106
autoFocus
107+
{...AppInputProps}
106108
testID="track_event_name_input"
107109
/>
108110
<Text style={styles.label}>Properties (optional, JSON)</Text>
@@ -117,6 +119,7 @@ export default function TrackEventModal({
117119
value={propertiesText}
118120
onChangeText={handlePropertiesChange}
119121
multiline
122+
{...AppInputProps}
120123
testID="track_event_properties_input"
121124
/>
122125
{!!jsonError && <Text style={styles.errorText}>{jsonError}</Text>}

examples/demo/src/components/sections/SendPushSection.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import { NotificationType } from '../../models/NotificationType';
77
interface Props {
88
onSendNotification: (type: NotificationType) => void;
99
onSendCustomNotification: (title: string, body: string) => void;
10+
onClearAll: () => void;
1011
onInfoTap?: () => void;
1112
}
1213

1314
export default function SendPushSection({
1415
onSendNotification,
1516
onSendCustomNotification,
17+
onClearAll,
1618
onInfoTap,
1719
}: Props) {
1820
const [customVisible, setCustomVisible] = useState(false);
@@ -34,6 +36,12 @@ export default function SendPushSection({
3436
onPress={() => setCustomVisible(true)}
3537
testID="send_custom_push_button"
3638
/>
39+
<ActionButton
40+
label="CLEAR ALL"
41+
variant="outlined"
42+
onPress={onClearAll}
43+
testID="clear_all_notifications_button"
44+
/>
3745
<CustomNotificationModal
3846
visible={customVisible}
3947
onConfirm={(title, body) => {

examples/demo/src/context/AppContext.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ type AppContextValue = {
257257
setPushEnabled: (enabled: boolean) => void;
258258
sendNotification: (type: NotificationType) => Promise<void>;
259259
sendCustomNotification: (title: string, body: string) => Promise<void>;
260+
clearAllNotifications: () => void;
260261
setIamPaused: (paused: boolean) => Promise<void>;
261262
sendIamTrigger: (iamType: string) => void;
262263
addAlias: (label: string, id: string) => void;
@@ -551,6 +552,12 @@ export function AppContextProvider({ children }: Props) {
551552
[],
552553
);
553554

555+
const clearAllNotifications = useCallback(() => {
556+
repository.clearAllNotifications();
557+
log.i(TAG, 'All notifications cleared');
558+
Toast.show({ type: 'info', text1: 'All notifications cleared' });
559+
}, []);
560+
554561
const setIamPaused = useCallback(async (paused: boolean) => {
555562
dispatch({ type: 'SET_IAM_PAUSED', payload: paused });
556563
repository.setPaused(paused);
@@ -727,6 +734,7 @@ export function AppContextProvider({ children }: Props) {
727734
setPushEnabled,
728735
sendNotification,
729736
sendCustomNotification,
737+
clearAllNotifications,
730738
setIamPaused,
731739
sendIamTrigger,
732740
addAlias,
@@ -759,6 +767,7 @@ export function AppContextProvider({ children }: Props) {
759767
setPushEnabled,
760768
sendNotification,
761769
sendCustomNotification,
770+
clearAllNotifications,
762771
setIamPaused,
763772
sendIamTrigger,
764773
addAlias,

0 commit comments

Comments
 (0)