11import Material3Avatar from "@/components/material3-avatar" ;
22import PhoneNumberInput from "@/components/phone-number-input" ;
3+ import { additionalFields } from "@/constants/AdditionalFields" ;
34import { getAvatarColor } from "@/lib/avatar-utils" ;
45import { getCountryByCode } from "@/lib/countries" ;
56import { Contact , ContactFormData } from "@/lib/types" ;
67import { getFormattedDate , getVisibleFields , trimDialCode } from "@/lib/utils" ;
78import useContactStore from "@/store/contactStore" ;
8- import BottomSheet , {
9- BottomSheetBackdrop ,
10- BottomSheetScrollView ,
11- BottomSheetView ,
12- } from "@gorhom/bottom-sheet" ;
139import { router , useLocalSearchParams } from "expo-router" ;
1410import React , { useState } from "react" ;
1511import { Controller , useForm } from "react-hook-form" ;
@@ -22,20 +18,22 @@ import {
2218 StyleSheet ,
2319 View ,
2420} from "react-native" ;
21+ import { SheetManager } from "react-native-actions-sheet" ;
2522import DatePicker from "react-native-date-picker" ;
2623import {
2724 Button ,
2825 HelperText ,
29- List ,
3026 Portal ,
3127 Snackbar ,
3228 Text ,
3329 TextInput ,
3430 useTheme ,
3531} from "react-native-paper" ;
32+ import { useSafeAreaInsets } from "react-native-safe-area-context" ;
3633
3734export default function EditContactScreen ( ) {
3835 const theme = useTheme ( ) ;
36+ const insets = useSafeAreaInsets ( ) ;
3937 const { contact : contactParam , index } = useLocalSearchParams ( ) ;
4038
4139 // Parse the contact from JSON string
@@ -58,27 +56,6 @@ export default function EditContactScreen() {
5856 contact ?. birthday ? new Date ( contact . birthday ) : new Date ( )
5957 ) ;
6058
61- // Bottom sheet ref and snap points
62- const bottomSheetModalRef = React . useRef < BottomSheet > ( null ) ;
63-
64- const additionalFields = [
65- { key : "prefix" , label : "Prefix" , icon : "account-arrow-left-outline" } ,
66- { key : "suffix" , label : "Suffix" , icon : "account-arrow-right-outline" } ,
67- { key : "email" , label : "Email" , icon : "email-outline" } ,
68- { key : "notes" , label : "Notes" , icon : "note-text-outline" } ,
69- { key : "website" , label : "Website" , icon : "link" } ,
70- { key : "birthday" , label : "Birthday" , icon : "cake-variant-outline" } ,
71- { key : "nickname" , label : "Nickname" , icon : "account-heart-outline" } ,
72- ] ;
73-
74- const openBottomSheet = React . useCallback ( ( ) => {
75- bottomSheetModalRef . current ?. expand ( ) ;
76- } , [ ] ) ;
77-
78- const closeBottomSheet = React . useCallback ( ( ) => {
79- bottomSheetModalRef . current ?. close ( ) ;
80- } , [ ] ) ;
81-
8259 const [ avatarBackgroundColor , avatarTextColor ] = getAvatarColor (
8360 letter ,
8461 theme . dark ,
@@ -117,17 +94,6 @@ export default function EditContactScreen() {
11794
11895 const onDismissSnackBar = ( ) => setVisible ( false ) ;
11996
120- const toggleField = ( fieldKey : string ) => {
121- const newVisibleFields = new Set ( visibleFields ) ;
122- if ( newVisibleFields . has ( fieldKey ) ) {
123- newVisibleFields . delete ( fieldKey ) ;
124- } else {
125- newVisibleFields . add ( fieldKey ) ;
126- }
127- setVisibleFields ( newVisibleFields ) ;
128- closeBottomSheet ( ) ;
129- } ;
130-
13197 const removeFieldAndReset = ( fieldKey : string ) => {
13298 const newVisibleFields = new Set ( visibleFields ) ;
13399 newVisibleFields . delete ( fieldKey ) ;
@@ -252,7 +218,7 @@ export default function EditContactScreen() {
252218 } ) ;
253219
254220 if ( success ) {
255- router . replace ( "/" ) ;
221+ router . dismissAll ( ) ;
256222 } else {
257223 setVisible ( true ) ;
258224 }
@@ -272,9 +238,14 @@ export default function EditContactScreen() {
272238 return (
273239 < KeyboardAvoidingView
274240 behavior = { Platform . OS === "ios" ? "padding" : "height" }
275- style = { styles . container }
241+ style = { [ styles . container , { paddingBottom : insets . bottom } ] }
276242 >
277- < ScrollView contentContainerStyle = { styles . scrollContent } >
243+ < ScrollView
244+ contentContainerStyle = { [
245+ styles . scrollContent ,
246+ { paddingBottom : insets . bottom } ,
247+ ] }
248+ >
278249 < View style = { styles . formContainer } >
279250 < Material3Avatar
280251 letter = { letter }
@@ -369,7 +340,11 @@ export default function EditContactScreen() {
369340 < View style = { styles . buttonContainer } >
370341 < Button
371342 mode = "contained-tonal"
372- onPress = { openBottomSheet }
343+ onPress = { ( ) =>
344+ SheetManager . show ( "additional-field-sheet" , {
345+ payload : { visibleFields, setVisibleFields } ,
346+ } )
347+ }
373348 style = { styles . addFieldButton }
374349 labelStyle = { { fontSize : 16 } }
375350 disabled = {
@@ -393,59 +368,6 @@ export default function EditContactScreen() {
393368 </ ScrollView >
394369
395370 < Portal >
396- { /* Add Fields Bottom Sheet */ }
397- < BottomSheet
398- ref = { bottomSheetModalRef }
399- enableDynamicSizing = { false }
400- snapPoints = { [ "60%" ] }
401- index = { - 1 }
402- enablePanDownToClose = { true }
403- backdropComponent = { ( props ) => (
404- < BottomSheetBackdrop
405- { ...props }
406- appearsOnIndex = { 0 }
407- disappearsOnIndex = { - 1 }
408- />
409- ) }
410- backgroundStyle = { [
411- { backgroundColor : theme . colors . elevation . level2 } ,
412- styles . bottomSheetBackground ,
413- ] }
414- handleIndicatorStyle = { {
415- backgroundColor : theme . colors . onSurfaceVariant ,
416- } }
417- >
418- < BottomSheetView
419- style = { [
420- styles . header ,
421- {
422- borderBottomColor : theme . colors . outline ,
423- backgroundColor : theme . colors . elevation . level2 ,
424- } ,
425- ] }
426- >
427- < Text
428- variant = "headlineSmall"
429- style = { [ styles . title , { color : theme . colors . onSurface } ] }
430- >
431- Choose fields to add
432- </ Text >
433- </ BottomSheetView >
434- < BottomSheetScrollView style = { styles . bottomSheetContent } >
435- { additionalFields
436- . filter ( ( field ) => ! visibleFields . has ( field . key ) )
437- . map ( ( field , index ) => (
438- < List . Item
439- key = { field . key }
440- title = { field . label }
441- left = { ( ) => < List . Icon icon = { field . icon } /> }
442- onPress = { ( ) => toggleField ( field . key ) }
443- style = { styles . list }
444- />
445- ) ) }
446- </ BottomSheetScrollView >
447- </ BottomSheet >
448-
449371 < Snackbar
450372 visible = { visible }
451373 onDismiss = { onDismissSnackBar }
@@ -459,13 +381,6 @@ export default function EditContactScreen() {
459381 >
460382 { updateError || "An error occurred" }
461383 </ Snackbar >
462- { /* <Dialog visible={visible} onDismiss={hideDialog}>
463- <Dialog.Icon icon="alert" />
464- <Dialog.Title >This is a title</Dialog.Title>
465- <Dialog.Content>
466- <Text variant="bodyMedium">This is simple dialog</Text>
467- </Dialog.Content>
468- </Dialog> */ }
469384 </ Portal >
470385 </ KeyboardAvoidingView >
471386 ) ;
@@ -481,7 +396,6 @@ const styles = StyleSheet.create({
481396 } ,
482397 formContainer : {
483398 flex : 1 ,
484- padding : 16 ,
485399 paddingHorizontal : 16 ,
486400 gap : 16 ,
487401 } ,
0 commit comments