Skip to content

Commit 704133a

Browse files
feat(example): add set user identification and attribute
1 parent d28b209 commit 704133a

File tree

2 files changed

+173
-170
lines changed

2 files changed

+173
-170
lines changed

examples/default/src/navigation/RootTab.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Icon from 'react-native-vector-icons/Ionicons';
88

99
import { SettingsScreen } from '../screens/SettingsScreen';
1010
import { HomeStackNavigator } from './HomeStack';
11+
import { Platform } from 'react-native';
1112

1213
export type RootTabParamList = {
1314
HomeStack: undefined;
@@ -22,7 +23,7 @@ const createTabBarIcon = (name: string): BottomTabNavigationOptions['tabBarIcon'
2223

2324
export const RootTabNavigator: React.FC = () => {
2425
return (
25-
<RootTab.Navigator>
26+
<RootTab.Navigator screenOptions={{ tabBarHideOnKeyboard: Platform.OS !== 'ios' }}>
2627
<RootTab.Screen
2728
name="HomeStack"
2829
component={HomeStackNavigator}

examples/default/src/screens/SettingsScreen.tsx

Lines changed: 171 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Input, InputGroup, InputLeftAddon, useToast, VStack, Button, Text } fro
66
import { ListTile } from '../components/ListTile';
77
import { Screen } from '../components/Screen';
88
import { Select } from '../components/Select';
9-
import { StyleSheet, View } from 'react-native';
9+
import { StyleSheet, View, ScrollView } from 'react-native';
1010
import { VerticalListTile } from '../components/VerticalListTile';
1111

1212
export const SettingsScreen: React.FC = () => {
@@ -45,183 +45,185 @@ export const SettingsScreen: React.FC = () => {
4545
});
4646

4747
return (
48-
<Screen>
49-
<ListTile title="Invocation Event">
50-
<Select
51-
label="Select Invocation Event"
52-
items={[
53-
{
54-
label: 'None',
55-
value: InvocationEvent.none,
56-
},
57-
{
58-
label: 'Shake',
59-
value: InvocationEvent.shake,
60-
},
61-
{
62-
label: 'Screenshot',
63-
value: InvocationEvent.screenshot,
64-
},
65-
{
66-
label: 'Two fingers swipe left',
67-
value: InvocationEvent.twoFingersSwipe,
68-
},
69-
{
70-
label: 'Floating button',
71-
value: InvocationEvent.floatingButton,
72-
isInitial: true,
73-
},
74-
]}
75-
onValueChange={(value) => {
76-
BugReporting.setInvocationEvents([value]);
77-
}}
78-
/>
79-
</ListTile>
80-
81-
<ListTile title="Primary Color">
82-
<InputGroup>
83-
<InputLeftAddon>#</InputLeftAddon>
84-
<Input
85-
value={color}
86-
maxLength={6}
87-
flex={1}
88-
accessibilityLabel="Primary Color Value"
89-
onChangeText={(value) => {
90-
setColor(value);
91-
if (/^[0-9A-F]{6}$/i.test(value)) {
92-
Instabug.setPrimaryColor(`#${value}`);
93-
}
48+
<ScrollView>
49+
<Screen>
50+
<ListTile title="Invocation Event">
51+
<Select
52+
label="Select Invocation Event"
53+
items={[
54+
{
55+
label: 'None',
56+
value: InvocationEvent.none,
57+
},
58+
{
59+
label: 'Shake',
60+
value: InvocationEvent.shake,
61+
},
62+
{
63+
label: 'Screenshot',
64+
value: InvocationEvent.screenshot,
65+
},
66+
{
67+
label: 'Two fingers swipe left',
68+
value: InvocationEvent.twoFingersSwipe,
69+
},
70+
{
71+
label: 'Floating button',
72+
value: InvocationEvent.floatingButton,
73+
isInitial: true,
74+
},
75+
]}
76+
onValueChange={(value) => {
77+
BugReporting.setInvocationEvents([value]);
9478
}}
9579
/>
96-
</InputGroup>
97-
</ListTile>
80+
</ListTile>
9881

99-
<ListTile title="Theme">
100-
<Select
101-
label="Select Theme"
102-
items={[
103-
{
104-
label: 'Light',
105-
value: ColorTheme.light,
106-
},
107-
{
108-
label: 'Dark',
109-
value: ColorTheme.dark,
110-
},
111-
]}
112-
onValueChange={Instabug.setColorTheme}
113-
/>
114-
</ListTile>
82+
<ListTile title="Primary Color">
83+
<InputGroup>
84+
<InputLeftAddon>#</InputLeftAddon>
85+
<Input
86+
value={color}
87+
maxLength={6}
88+
flex={1}
89+
accessibilityLabel="Primary Color Value"
90+
onChangeText={(value) => {
91+
setColor(value);
92+
if (/^[0-9A-F]{6}$/i.test(value)) {
93+
Instabug.setPrimaryColor(`#${value}`);
94+
}
95+
}}
96+
/>
97+
</InputGroup>
98+
</ListTile>
11599

116-
<VerticalListTile title="User Identification">
117-
<VStack>
118-
<View style={styles.formContainer}>
119-
<View style={styles.inputWrapper}>
120-
<Input
121-
placeholder="User Email"
122-
keyboardType="email-address"
123-
onChangeText={(name) => setUserEmail(name)}
124-
defaultValue={userEmail}
125-
/>
126-
</View>
127-
<View style={styles.inputWrapper}>
128-
<Input
129-
placeholder=" user name"
130-
onChangeText={(name) => setUserName(name)}
131-
defaultValue={userName}
132-
/>
133-
</View>
134-
<View style={styles.inputWrapper}>
135-
<Input
136-
placeholder=" user id"
137-
onChangeText={(name) => setUserID(name)}
138-
defaultValue={userID}
139-
/>
140-
</View>
141-
</View>
142-
<Button
143-
mt="4"
144-
onPress={() => {
145-
Instabug.identifyUser(userEmail, userName, userID);
146-
setUserID('');
147-
setUserName('');
148-
setUserEmail('');
149-
toast.show({
150-
description: 'User identified successfully',
151-
});
152-
}}>
153-
Identify user
154-
</Button>
100+
<ListTile title="Theme">
101+
<Select
102+
label="Select Theme"
103+
items={[
104+
{
105+
label: 'Light',
106+
value: ColorTheme.light,
107+
},
108+
{
109+
label: 'Dark',
110+
value: ColorTheme.dark,
111+
},
112+
]}
113+
onValueChange={Instabug.setColorTheme}
114+
/>
115+
</ListTile>
155116

156-
<Button
157-
mt="4"
158-
colorScheme="red"
159-
onPress={() => {
160-
Instabug.logOut();
161-
toast.show({
162-
description: 'User logout successfully',
163-
});
164-
setUserID('');
165-
setUserName('');
166-
setUserEmail('');
167-
}}>
168-
Logout user
169-
</Button>
170-
</VStack>
171-
</VerticalListTile>
172-
<VerticalListTile title="User Attributes">
173-
<VStack>
174-
<View style={styles.formContainer}>
175-
<View style={styles.inputWrapper}>
176-
<Input
177-
placeholder="User attribute key"
178-
onChangeText={(key) => setUserAttributeKey(key)}
179-
defaultValue={userAttributeKey}
180-
/>
181-
{userAttributesFormError.userAttributeKey ? (
182-
<Text style={styles.errorText}>{userAttributesFormError.userAttributeKey}</Text>
183-
) : null}
184-
</View>
185-
<View style={styles.inputWrapper}>
186-
<Input
187-
placeholder="User attribute value"
188-
onChangeText={(value) => setUserAttributeValue(value)}
189-
defaultValue={userAttributeValue}
190-
/>
191-
{userAttributesFormError.userAttributeValue ? (
192-
<Text style={styles.errorText}>{userAttributesFormError.userAttributeValue}</Text>
193-
) : null}
117+
<VerticalListTile title="User Identification">
118+
<VStack>
119+
<View style={styles.formContainer}>
120+
<View style={styles.inputWrapper}>
121+
<Input
122+
placeholder="User Email"
123+
keyboardType="email-address"
124+
onChangeText={(name) => setUserEmail(name)}
125+
defaultValue={userEmail}
126+
/>
127+
</View>
128+
<View style={styles.inputWrapper}>
129+
<Input
130+
placeholder=" user name"
131+
onChangeText={(name) => setUserName(name)}
132+
defaultValue={userName}
133+
/>
134+
</View>
135+
<View style={styles.inputWrapper}>
136+
<Input
137+
placeholder=" user id"
138+
onChangeText={(name) => setUserID(name)}
139+
defaultValue={userID}
140+
/>
141+
</View>
194142
</View>
195-
</View>
143+
<Button
144+
mt="4"
145+
onPress={() => {
146+
Instabug.identifyUser(userEmail, userName, userID);
147+
setUserID('');
148+
setUserName('');
149+
setUserEmail('');
150+
toast.show({
151+
description: 'User identified successfully',
152+
});
153+
}}>
154+
Identify user
155+
</Button>
196156

197-
<Button
198-
mt="4"
199-
onPress={() => {
200-
if (validateUserAttributeForm()) {
201-
Instabug.setUserAttribute(userAttributeKey, userAttributeValue);
157+
<Button
158+
mt="4"
159+
colorScheme="red"
160+
onPress={() => {
161+
Instabug.logOut();
202162
toast.show({
203-
description: 'User Attributes added successfully',
163+
description: 'User logout successfully',
204164
});
205-
setUserAttributeKey('');
206-
setUserAttributeValue('');
207-
}
208-
}}>
209-
Save user attributes
210-
</Button>
165+
setUserID('');
166+
setUserName('');
167+
setUserEmail('');
168+
}}>
169+
Logout user
170+
</Button>
171+
</VStack>
172+
</VerticalListTile>
173+
<VerticalListTile title="User Attributes">
174+
<VStack>
175+
<View style={styles.formContainer}>
176+
<View style={styles.inputWrapper}>
177+
<Input
178+
placeholder="User attribute key"
179+
onChangeText={(key) => setUserAttributeKey(key)}
180+
defaultValue={userAttributeKey}
181+
/>
182+
{userAttributesFormError.userAttributeKey ? (
183+
<Text style={styles.errorText}>{userAttributesFormError.userAttributeKey}</Text>
184+
) : null}
185+
</View>
186+
<View style={styles.inputWrapper}>
187+
<Input
188+
placeholder="User attribute value"
189+
onChangeText={(value) => setUserAttributeValue(value)}
190+
defaultValue={userAttributeValue}
191+
/>
192+
{userAttributesFormError.userAttributeValue ? (
193+
<Text style={styles.errorText}>{userAttributesFormError.userAttributeValue}</Text>
194+
) : null}
195+
</View>
196+
</View>
211197

212-
<Button
213-
mt="4"
214-
colorScheme="red"
215-
onPress={() => {
216-
Instabug.clearAllUserAttributes();
217-
toast.show({
218-
description: 'User Attributes cleared successfully',
219-
});
220-
}}>
221-
Clear user attributes
222-
</Button>
223-
</VStack>
224-
</VerticalListTile>
225-
</Screen>
198+
<Button
199+
mt="4"
200+
onPress={() => {
201+
if (validateUserAttributeForm()) {
202+
Instabug.setUserAttribute(userAttributeKey, userAttributeValue);
203+
toast.show({
204+
description: 'User Attributes added successfully',
205+
});
206+
setUserAttributeKey('');
207+
setUserAttributeValue('');
208+
}
209+
}}>
210+
Save user attributes
211+
</Button>
212+
213+
<Button
214+
mt="4"
215+
colorScheme="red"
216+
onPress={() => {
217+
Instabug.clearAllUserAttributes();
218+
toast.show({
219+
description: 'User Attributes cleared successfully',
220+
});
221+
}}>
222+
Clear user attributes
223+
</Button>
224+
</VStack>
225+
</VerticalListTile>
226+
</Screen>
227+
</ScrollView>
226228
);
227229
};

0 commit comments

Comments
 (0)