Skip to content

Commit 7306bf2

Browse files
authored
example: toolbar in modal (#869)
## 📜 Description I added it many times already, so let's include in example app. ## 💡 Motivation and Context Sometimes I have to test how `KeyboardToolbar` works in `Modal`, so I decided to include that example in test app so that I don't need to make these changes every time. Reproduction for #867 ## 📢 Changelog <!-- High level overview of important changes --> <!-- For example: fixed status bar manipulation; added new types declarations; --> <!-- If your changes don't affect one of platform/language below - then remove this platform/language --> ### JS - added KYC button in `KeyboardToolbar` screen; ## 🤔 How Has This Been Tested? Tested on Android (Medium Phone API 35) and iOS (iPhone 15 Pro, iOS 17.5) simulators. ## 📸 Screenshots (if appropriate): |Android|iOS| |--------|---| |<img width="380" alt="image" src="https://github.com/user-attachments/assets/0e3207fa-4adc-4548-aea3-035da822d639" />|<image width="380" src="https://github.com/user-attachments/assets/b5be7588-b1e8-4aa2-ba4d-509ba6186f52">| ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed
1 parent cb8161c commit 7306bf2

2 files changed

Lines changed: 98 additions & 6 deletions

File tree

  • FabricExample/src/screens/Examples/Toolbar
  • example/src/screens/Examples/Toolbar

FabricExample/src/screens/Examples/Toolbar/index.tsx

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BlurView } from "@react-native-community/blur";
2-
import React, { useCallback, useState } from "react";
3-
import { Platform, StyleSheet, View } from "react-native";
2+
import React, { useCallback, useEffect, useState } from "react";
3+
import { Modal, Platform, StyleSheet, Text, View } from "react-native";
44
import { trigger } from "react-native-haptic-feedback";
55
import {
66
KeyboardAwareScrollView,
@@ -13,6 +13,8 @@ import TextInput from "../../../components/TextInput";
1313
import AutoFillContacts from "./Contacts";
1414

1515
import type { Contact } from "./Contacts";
16+
import type { ExamplesStackParamList } from "../../../navigation/ExamplesStack";
17+
import type { StackScreenProps } from "@react-navigation/stack";
1618

1719
// Optional configuration
1820
const options = {
@@ -22,7 +24,7 @@ const options = {
2224
const haptic = () =>
2325
trigger(Platform.OS === "ios" ? "impactLight" : "keyboardTap", options);
2426

25-
export default function ToolbarExample() {
27+
function Form() {
2628
const [showAutoFill, setShowAutoFill] = useState(false);
2729
const [name, setName] = useState("");
2830
const onContactSelected = useCallback((contact: Contact) => {
@@ -170,6 +172,44 @@ export default function ToolbarExample() {
170172
);
171173
}
172174

175+
type Props = StackScreenProps<ExamplesStackParamList>;
176+
177+
export default function ToolbarExample({ navigation }: Props) {
178+
const [isVisible, setVisible] = useState(false);
179+
180+
useEffect(() => {
181+
navigation.setOptions({
182+
headerRight: () => (
183+
<View style={styles.row}>
184+
<Text
185+
style={styles.header}
186+
testID="toolbar.kyc"
187+
onPress={() => setVisible(true)}
188+
>
189+
KYC
190+
</Text>
191+
</View>
192+
),
193+
});
194+
}, [navigation]);
195+
196+
return (
197+
<>
198+
<Form />
199+
<Modal
200+
animationType="slide"
201+
presentationStyle="formSheet"
202+
visible={isVisible}
203+
onRequestClose={() => setVisible(false)}
204+
>
205+
<View style={styles.modal}>
206+
<Form />
207+
</View>
208+
</Modal>
209+
</>
210+
);
211+
}
212+
173213
const styles = StyleSheet.create({
174214
container: {
175215
backgroundColor: "white",
@@ -190,6 +230,12 @@ const styles = StyleSheet.create({
190230
bottom: 0,
191231
right: 0,
192232
},
233+
header: {
234+
marginRight: 12,
235+
},
236+
modal: {
237+
marginTop: 32,
238+
},
193239
});
194240

195241
const blur = (

example/src/screens/Examples/Toolbar/index.tsx

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BlurView } from "@react-native-community/blur";
2-
import React, { useCallback, useState } from "react";
3-
import { Platform, StyleSheet, View } from "react-native";
2+
import React, { useCallback, useEffect, useState } from "react";
3+
import { Modal, Platform, StyleSheet, Text, View } from "react-native";
44
import { trigger } from "react-native-haptic-feedback";
55
import {
66
KeyboardAwareScrollView,
@@ -13,6 +13,8 @@ import TextInput from "../../../components/TextInput";
1313
import AutoFillContacts from "./Contacts";
1414

1515
import type { Contact } from "./Contacts";
16+
import type { ExamplesStackParamList } from "../../../navigation/ExamplesStack";
17+
import type { StackScreenProps } from "@react-navigation/stack";
1618

1719
// Optional configuration
1820
const options = {
@@ -22,7 +24,7 @@ const options = {
2224
const haptic = () =>
2325
trigger(Platform.OS === "ios" ? "impactLight" : "keyboardTap", options);
2426

25-
export default function ToolbarExample() {
27+
function Form() {
2628
const [showAutoFill, setShowAutoFill] = useState(false);
2729
const [name, setName] = useState("");
2830
const onContactSelected = useCallback((contact: Contact) => {
@@ -170,6 +172,44 @@ export default function ToolbarExample() {
170172
);
171173
}
172174

175+
type Props = StackScreenProps<ExamplesStackParamList>;
176+
177+
export default function ToolbarExample({ navigation }: Props) {
178+
const [isVisible, setVisible] = useState(false);
179+
180+
useEffect(() => {
181+
navigation.setOptions({
182+
headerRight: () => (
183+
<View style={styles.row}>
184+
<Text
185+
style={styles.header}
186+
testID="toolbar.kyc"
187+
onPress={() => setVisible(true)}
188+
>
189+
KYC
190+
</Text>
191+
</View>
192+
),
193+
});
194+
}, [navigation]);
195+
196+
return (
197+
<>
198+
<Form />
199+
<Modal
200+
animationType="slide"
201+
presentationStyle="formSheet"
202+
visible={isVisible}
203+
onRequestClose={() => setVisible(false)}
204+
>
205+
<View style={styles.modal}>
206+
<Form />
207+
</View>
208+
</Modal>
209+
</>
210+
);
211+
}
212+
173213
const styles = StyleSheet.create({
174214
container: {
175215
backgroundColor: "white",
@@ -190,6 +230,12 @@ const styles = StyleSheet.create({
190230
bottom: 0,
191231
right: 0,
192232
},
233+
header: {
234+
marginRight: 12,
235+
},
236+
modal: {
237+
marginTop: 32,
238+
},
193239
});
194240

195241
const blur = (

0 commit comments

Comments
 (0)