-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
445 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import {FlatList, Image, Pressable, View} from 'react-native'; | ||
import React from 'react'; | ||
import {Text, useTheme} from 'react-native-paper'; | ||
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons'; | ||
import {useState} from 'react'; | ||
import {useEffect} from 'react'; | ||
|
||
export const ImageAttachmentGallery = ({ | ||
URIs, | ||
removeURI, | ||
imageToView, | ||
setImageToView, | ||
}) => { | ||
const theme = useTheme(); | ||
|
||
const _renderURIImages = ({item, index}) => { | ||
const _split = String(item).split('/'); | ||
|
||
return ( | ||
<Pressable | ||
style={{position: 'relative', marginRight: 12}} | ||
onPress={() => | ||
setImageToView({ | ||
images: URIs?.map(uri => { | ||
return {uri}; | ||
}), | ||
index: index, | ||
visible: true, | ||
}) | ||
}> | ||
<Image | ||
source={{uri: item}} | ||
style={{height: 120, width: 200, borderRadius: 6}} | ||
/> | ||
<Pressable | ||
onPress={() => removeURI(item)} | ||
style={{ | ||
position: 'absolute', | ||
top: 6, | ||
right: 6, | ||
|
||
backgroundColor: theme?.colors.backdrop, | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
padding: 6, | ||
borderRadius: 20, | ||
}}> | ||
<MaterialCommunityIcons | ||
name="close" | ||
color={theme?.colors.surface} | ||
size={12} | ||
style={{padding: 0}} | ||
/> | ||
</Pressable> | ||
</Pressable> | ||
); | ||
}; | ||
return ( | ||
<View> | ||
<FlatList | ||
data={URIs} | ||
horizontal={true} | ||
contentContainerStyle={{padding: 12}} | ||
renderItem={_renderURIImages} | ||
keyExtractor={(item, index) => item} | ||
/> | ||
</View> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
import BottomSheet, { | ||
BottomSheetBackdrop, | ||
BottomSheetFlatList, | ||
BottomSheetView, | ||
useBottomSheetDynamicSnapPoints, | ||
} from '@gorhom/bottom-sheet'; | ||
import {launchCamera, launchImageLibrary} from 'react-native-image-picker'; | ||
import withObservables from '@nozbe/with-observables'; | ||
import React, {useCallback, useEffect, useMemo, useRef} from 'react'; | ||
import {Pressable, View} from 'react-native'; | ||
import { | ||
Appbar, | ||
Divider, | ||
IconButton, | ||
List, | ||
Surface, | ||
Text, | ||
TouchableRipple, | ||
useTheme, | ||
} from 'react-native-paper'; | ||
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons'; | ||
import {database} from '../db/db'; | ||
import Label from '../db/models/Label'; | ||
import {Logger} from '../utils/logger'; | ||
|
||
export const ImagePickerBottomSheet = ({ | ||
visible, | ||
setVisible, | ||
addURI, | ||
removeURI, | ||
}) => { | ||
// hooks | ||
const sheetRef = useRef(null); | ||
const theme = useTheme(); | ||
|
||
const snapPoints = useMemo(() => ['CONTENT_HEIGHT'], []); | ||
|
||
const { | ||
animatedHandleHeight, | ||
animatedSnapPoints, | ||
animatedContentHeight, | ||
handleContentLayout, | ||
} = useBottomSheetDynamicSnapPoints(snapPoints); | ||
|
||
useEffect(() => { | ||
if (!visible) { | ||
_handleCloseFilterSheet(); | ||
} else { | ||
_handleOpenFilterSheet(0); | ||
} | ||
}, [visible, sheetRef]); | ||
|
||
// callbacks | ||
const _handleSheetChange = useCallback(index => {}, []); | ||
const _handleOpenFilterSheet = useCallback(index => { | ||
sheetRef.current?.snapToIndex(index); | ||
}, []); | ||
const _handleCloseFilterSheet = useCallback(() => { | ||
sheetRef.current?.close(); | ||
}, []); | ||
|
||
const _renderBackdrop = useCallback( | ||
props => ( | ||
<BottomSheetBackdrop | ||
{...props} | ||
appearsOnIndex={0} | ||
disappearsOnIndex={-1} | ||
opacity={0.4} | ||
/> | ||
), | ||
[], | ||
); | ||
|
||
const _handleOpenCamera = async () => { | ||
const result = await launchCamera({saveToPhotos: true}); | ||
if (result.didCancel || result.errorCode) { | ||
Logger.pageLogger( | ||
'ImagePickerBottomSheet.js:_handleOpenCamera:cancel or error', | ||
result.errorMessage, | ||
); | ||
} else { | ||
if ( | ||
result.assets && | ||
Array.isArray(result.assets) && | ||
result.assets.length > 0 | ||
) { | ||
addURI(result.assets[0].uri); | ||
} | ||
Logger.pageLogger( | ||
'ImagePickerBottomSheet.js:_handleOpenCamera:result', | ||
result, | ||
); | ||
} | ||
setVisible(false); | ||
}; | ||
|
||
const _handleOpenFileSystem = async () => { | ||
const result = await launchImageLibrary(); | ||
if (result.didCancel || result.errorCode) { | ||
Logger.pageLogger( | ||
'ImagePickerBottomSheet.js:_handleOpenFileSystem:cancel or error', | ||
result.errorMessage, | ||
); | ||
} else { | ||
if ( | ||
result.assets && | ||
Array.isArray(result.assets) && | ||
result.assets.length > 0 | ||
) { | ||
addURI(result.assets[0].uri); | ||
} | ||
Logger.pageLogger( | ||
'ImagePickerBottomSheet.js:_handleOpenFileSystem:result', | ||
result, | ||
); | ||
} | ||
setVisible(false); | ||
}; | ||
|
||
return ( | ||
<BottomSheet | ||
ref={sheetRef} | ||
index={-1} | ||
snapPoints={animatedSnapPoints} | ||
handleHeight={animatedHandleHeight} | ||
contentHeight={animatedContentHeight} | ||
backgroundStyle={{borderRadius: 6}} | ||
enablePanDownToClose={false} | ||
handleStyle={{display: 'none'}} | ||
backdropComponent={_renderBackdrop} | ||
onClose={() => setVisible(false)} | ||
onChange={_handleSheetChange}> | ||
<BottomSheetView onLayout={handleContentLayout}> | ||
<View | ||
style={{ | ||
width: '100%', | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
paddingHorizontal: 12, | ||
}}> | ||
<Text>Upload from</Text> | ||
<IconButton | ||
icon={'close'} | ||
onPress={() => { | ||
setVisible(false); | ||
}} | ||
/> | ||
</View> | ||
|
||
<Surface | ||
elevation={0} | ||
style={{ | ||
width: '100%', | ||
flexDirection: 'column', | ||
justifyContent: 'flex-start', | ||
alignItems: 'flex-start', | ||
}}> | ||
<List.Item | ||
left={() => <List.Icon icon={'folder'} />} | ||
style={{width: '100%', paddingVertical: 0}} | ||
onPress={_handleOpenFileSystem} | ||
title="From files" | ||
titleEllipsizeMode="tail" | ||
/> | ||
<List.Item | ||
left={() => <List.Icon icon={'camera'} />} | ||
style={{width: '100%', paddingVertical: 0}} | ||
onPress={_handleOpenCamera} | ||
title="Camera" | ||
titleEllipsizeMode="tail" | ||
/> | ||
</Surface> | ||
</BottomSheetView> | ||
</BottomSheet> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.