|
|
|
@ -1,4 +1,4 @@
@@ -1,4 +1,4 @@
|
|
|
|
|
import React, { useEffect, useMemo, useRef, useState } from 'react' |
|
|
|
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' |
|
|
|
|
import { |
|
|
|
|
View, |
|
|
|
|
Text, |
|
|
|
@ -7,7 +7,6 @@ import {
@@ -7,7 +7,6 @@ import {
|
|
|
|
|
TouchableOpacity, |
|
|
|
|
Dimensions, |
|
|
|
|
} from 'react-native' |
|
|
|
|
import RBSheet from 'react-native-raw-bottom-sheet' |
|
|
|
|
import _ from 'lodash' |
|
|
|
|
|
|
|
|
|
import { contactsService, tasksService } from '@/services/domain' |
|
|
|
@ -16,6 +15,7 @@ import {
@@ -16,6 +15,7 @@ import {
|
|
|
|
|
Button, |
|
|
|
|
isAndroid, |
|
|
|
|
IShortUser, |
|
|
|
|
KeyboardSpacer, |
|
|
|
|
SearchForm, |
|
|
|
|
Txt, |
|
|
|
|
useEventsListener, |
|
|
|
@ -26,6 +26,11 @@ import { selectUserModalTransforms } from './transforms'
@@ -26,6 +26,11 @@ import { selectUserModalTransforms } from './transforms'
|
|
|
|
|
import { usersService } from '@/services/domain/users.service' |
|
|
|
|
import { FetchType } from './intefaces' |
|
|
|
|
import { PartialTheme } from '@/shared/themes/interfaces' |
|
|
|
|
import { |
|
|
|
|
BottomSheetModal, |
|
|
|
|
BottomSheetBackdrop, |
|
|
|
|
BottomSheetTextInput, |
|
|
|
|
} from '@gorhom/bottom-sheet' |
|
|
|
|
|
|
|
|
|
const screenHeight = Dimensions.get('screen').height |
|
|
|
|
|
|
|
|
@ -40,13 +45,14 @@ const api = {
@@ -40,13 +45,14 @@ const api = {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const SelectUserModalSmart = () => { |
|
|
|
|
const { styles } = useTheme(createStyles) |
|
|
|
|
const sheetRef = useRef<RBSheet>(null) |
|
|
|
|
const { styles, theme } = useTheme(createStyles) |
|
|
|
|
const sheetRef = useRef<BottomSheetModal>(null) |
|
|
|
|
const settingsRef = useRef<ISettingsProps>({ callback: null }) |
|
|
|
|
const [type, setType] = useState<FetchType>(null) |
|
|
|
|
const [title, setTitle] = useState<string>('') |
|
|
|
|
const [isFocus, setFocus] = useState(false) |
|
|
|
|
|
|
|
|
|
const [modalHeight, setModalHeight] = useState(screenHeight - $size(250)) |
|
|
|
|
const [modalHeight, setModalHeight] = useState(screenHeight - 100) |
|
|
|
|
|
|
|
|
|
const [selectedItem, selectItem] = useState<IShortUser>({} as any) |
|
|
|
|
const [searchString, setsearchString] = useState<string>() |
|
|
|
@ -66,7 +72,7 @@ export const SelectUserModalSmart = () => {
@@ -66,7 +72,7 @@ export const SelectUserModalSmart = () => {
|
|
|
|
|
callback: data.callback, |
|
|
|
|
} |
|
|
|
|
setType(_.defaultTo(data.type, 'users')) |
|
|
|
|
sheetRef.current.open() |
|
|
|
|
sheetRef.current.present() |
|
|
|
|
if (data.title) setTitle(data.title) |
|
|
|
|
} catch (e) { |
|
|
|
|
console.log(e) |
|
|
|
@ -87,6 +93,17 @@ export const SelectUserModalSmart = () => {
@@ -87,6 +93,17 @@ export const SelectUserModalSmart = () => {
|
|
|
|
|
if (!_.isEmpty(selectedItem)) settingsRef.current.callback(selectedItem) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const renderBackdrop = useCallback( |
|
|
|
|
props => ( |
|
|
|
|
<BottomSheetBackdrop |
|
|
|
|
{...props} |
|
|
|
|
disappearsOnIndex={-1} |
|
|
|
|
appearsOnIndex={0} |
|
|
|
|
/> |
|
|
|
|
), |
|
|
|
|
[], |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
const renderItem = ({ item }) => { |
|
|
|
|
const isActive = selectedItem.id === item.id |
|
|
|
|
|
|
|
|
@ -113,36 +130,30 @@ export const SelectUserModalSmart = () => {
@@ -113,36 +130,30 @@ export const SelectUserModalSmart = () => {
|
|
|
|
|
searchValue={searchString} |
|
|
|
|
placeholder="Пошук" |
|
|
|
|
onChange={setsearchString} |
|
|
|
|
onFocus={() => |
|
|
|
|
setModalHeight(screenHeight - 220 - $size(100)) |
|
|
|
|
} |
|
|
|
|
onBlur={() => setModalHeight(screenHeight - $size(250))} |
|
|
|
|
onFocus={() => setFocus(true)} |
|
|
|
|
onBlur={() => setFocus(false)} |
|
|
|
|
paddingHorizontal={0} |
|
|
|
|
borderBottom={false} |
|
|
|
|
customInputComponent={BottomSheetTextInput} |
|
|
|
|
/> |
|
|
|
|
</View> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<RBSheet |
|
|
|
|
<BottomSheetModal |
|
|
|
|
name="select-user-modal" |
|
|
|
|
index={0} |
|
|
|
|
ref={sheetRef} |
|
|
|
|
height={modalHeight} |
|
|
|
|
dragFromTopOnly={true} |
|
|
|
|
closeOnDragDown={true} |
|
|
|
|
closeOnPressBack={true} |
|
|
|
|
closeOnPressMask={true} |
|
|
|
|
animationType="fade" |
|
|
|
|
onClose={() => { |
|
|
|
|
setModalHeight(screenHeight - $size(250)) |
|
|
|
|
}} |
|
|
|
|
customStyles={{ |
|
|
|
|
container: { ...styles.container, height: modalHeight }, |
|
|
|
|
draggableIcon: { |
|
|
|
|
width: $size(70), |
|
|
|
|
height: $size(2), |
|
|
|
|
}, |
|
|
|
|
}}> |
|
|
|
|
snapPoints={[modalHeight]} |
|
|
|
|
backgroundStyle={[ |
|
|
|
|
styles.container, |
|
|
|
|
isFocus ? styles.containerFocus : null, |
|
|
|
|
]} |
|
|
|
|
backdropComponent={renderBackdrop} |
|
|
|
|
keyboardBehavior="fillParent" |
|
|
|
|
keyboardBlurBehavior="restore" |
|
|
|
|
handleIndicatorStyle={isFocus ? { display: 'none' } : null}> |
|
|
|
|
<FlatList |
|
|
|
|
style={styles.list} |
|
|
|
|
data={list.items} |
|
|
|
@ -151,8 +162,10 @@ export const SelectUserModalSmart = () => {
@@ -151,8 +162,10 @@ export const SelectUserModalSmart = () => {
|
|
|
|
|
stickyHeaderIndices={[0]} |
|
|
|
|
onEndReached={() => list.loadMore()} |
|
|
|
|
showsVerticalScrollIndicator={false} |
|
|
|
|
contentContainerStyle={styles.listContent} |
|
|
|
|
keyboardShouldPersistTaps="handled" |
|
|
|
|
/> |
|
|
|
|
|
|
|
|
|
<View style={styles.content}> |
|
|
|
|
<Button |
|
|
|
|
title="Вибрати" |
|
|
|
|
type="primary" |
|
|
|
@ -161,7 +174,8 @@ export const SelectUserModalSmart = () => {
@@ -161,7 +174,8 @@ export const SelectUserModalSmart = () => {
|
|
|
|
|
sheetRef.current.close() |
|
|
|
|
}} |
|
|
|
|
/> |
|
|
|
|
</RBSheet> |
|
|
|
|
</View> |
|
|
|
|
</BottomSheetModal> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -170,11 +184,13 @@ const createStyles = (theme: PartialTheme) =>
@@ -170,11 +184,13 @@ const createStyles = (theme: PartialTheme) =>
|
|
|
|
|
container: { |
|
|
|
|
borderTopRightRadius: 35, |
|
|
|
|
borderTopLeftRadius: 35, |
|
|
|
|
paddingHorizontal: $size(20), |
|
|
|
|
paddingBottom: $size(30), |
|
|
|
|
backgroundColor: theme.$layoutBg, |
|
|
|
|
marginTop: isAndroid($size(20), 0), |
|
|
|
|
}, |
|
|
|
|
containerFocus: { |
|
|
|
|
borderTopRightRadius: 0, |
|
|
|
|
borderTopLeftRadius: 0, |
|
|
|
|
}, |
|
|
|
|
title: { |
|
|
|
|
textAlign: 'center', |
|
|
|
|
paddingVertical: 15, |
|
|
|
@ -182,6 +198,13 @@ const createStyles = (theme: PartialTheme) =>
@@ -182,6 +198,13 @@ const createStyles = (theme: PartialTheme) =>
|
|
|
|
|
fontSize: $size(22, 14), |
|
|
|
|
color: theme.$textPrimary, |
|
|
|
|
}, |
|
|
|
|
listContent: { |
|
|
|
|
paddingHorizontal: $size(20), |
|
|
|
|
}, |
|
|
|
|
content: { |
|
|
|
|
paddingHorizontal: $size(20), |
|
|
|
|
paddingBottom: $size(30), |
|
|
|
|
}, |
|
|
|
|
list: { |
|
|
|
|
flex: 1, |
|
|
|
|
}, |
|
|
|
|