@planningcenter/chat-react-native 3.4.1-rc.4 → 3.4.1-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/conversation/attachments/image_attachment.d.ts.map +1 -1
- package/build/components/conversation/attachments/image_attachment.js +18 -13
- package/build/components/conversation/attachments/image_attachment.js.map +1 -1
- package/build/components/display/image.d.ts +11 -2
- package/build/components/display/image.d.ts.map +1 -1
- package/build/components/display/image.js +5 -3
- package/build/components/display/image.js.map +1 -1
- package/package.json +2 -2
- package/src/components/conversation/attachments/image_attachment.tsx +30 -16
- package/src/components/display/image.tsx +17 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image_attachment.d.ts","sourceRoot":"","sources":["../../../../src/components/conversation/attachments/image_attachment.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"image_attachment.d.ts","sourceRoot":"","sources":["../../../../src/components/conversation/attachments/image_attachment.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAA;AA+B7D,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,wBAAgB,eAAe,CAAC,EAC9B,UAAU,EACV,SAAS,GACV,EAAE;IACD,UAAU,EAAE,GAAG,CAAA;IACf,SAAS,EAAE,SAAS,CAAA;CACrB,qBAuDA"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import React, { useCallback, useMemo, useState } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { StyleSheet, Modal, Pressable, useWindowDimensions, SafeAreaView, View, Linking, } from 'react-native';
|
|
3
3
|
import { Gesture, GestureDetector, GestureHandlerRootView, } from 'react-native-gesture-handler';
|
|
4
|
-
import
|
|
4
|
+
import { runOnJS, useAnimatedStyle, useSharedValue, withTiming, } from 'react-native-reanimated';
|
|
5
5
|
import { tokens } from '../../../vendor/tapestry/tokens';
|
|
6
|
-
import { IconButton, Heading, Text } from '../../display';
|
|
6
|
+
import { IconButton, Image, Heading, Text } from '../../display';
|
|
7
7
|
import colorFunction from 'color';
|
|
8
8
|
import { formatDatePreview } from '../../../utils/date';
|
|
9
9
|
const PAN_THRESHOLD_PX = 300;
|
|
10
10
|
export function ImageAttachment({ attachment, metaProps, }) {
|
|
11
|
-
const
|
|
11
|
+
const { attributes } = attachment;
|
|
12
|
+
const { url, urlMedium, filename, metadata = {} } = attributes;
|
|
13
|
+
const styles = useStyles({ imageWidth: metadata.width, imageHeight: metadata.height });
|
|
12
14
|
const [visible, setVisible] = useState(false);
|
|
13
15
|
// shared values run on the native UI thread and prevents clogging up the JS thread
|
|
14
16
|
const dismissY = useSharedValue(0);
|
|
@@ -33,13 +35,9 @@ export function ImageAttachment({ attachment, metaProps, }) {
|
|
|
33
35
|
transform: [{ translateY: dismissY.value }],
|
|
34
36
|
opacity: opacity.value,
|
|
35
37
|
}));
|
|
36
|
-
const { attributes } = attachment;
|
|
37
|
-
const { url, urlMedium, filename, metadata = {} } = attributes;
|
|
38
|
-
const width = metadata.width || 100;
|
|
39
|
-
const height = metadata.height || 100;
|
|
40
38
|
return (<>
|
|
41
39
|
<Pressable style={styles.container} onPress={() => setVisible(true)}>
|
|
42
|
-
<Image source={{ uri: urlMedium || url }} style={
|
|
40
|
+
<Image source={{ uri: urlMedium || url }} style={{ borderRadius: 8 }} wrapperStyle={styles.imageWrapper} alt={filename}/>
|
|
43
41
|
</Pressable>
|
|
44
42
|
<LightboxModal visible={visible} handleCloseModal={handleCloseModal} uri={urlMedium || url} metaProps={metaProps} panGesture={panGesture} animatedImageStyle={animatedImageStyle}/>
|
|
45
43
|
</>);
|
|
@@ -54,7 +52,7 @@ const LightboxModal = ({ uri, visible, handleCloseModal, metaProps, panGesture,
|
|
|
54
52
|
<SafeAreaView style={styles.modal}>
|
|
55
53
|
<GestureHandlerRootView>
|
|
56
54
|
<GestureDetector gesture={panGesture}>
|
|
57
|
-
<
|
|
55
|
+
<Image source={{ uri }} loadingBackgroundStyles={styles.lightboxImageLoading} style={styles.lightboxImage} animatedImageStyle={animatedImageStyle} resizeMode="contain" animated={true} alt=""/>
|
|
58
56
|
</GestureDetector>
|
|
59
57
|
<View style={styles.actionToolbar} accessibilityRole="toolbar">
|
|
60
58
|
<View style={styles.actionToolbarTextMeta}>
|
|
@@ -72,7 +70,7 @@ const LightboxModal = ({ uri, visible, handleCloseModal, metaProps, panGesture,
|
|
|
72
70
|
</SafeAreaView>
|
|
73
71
|
</Modal>);
|
|
74
72
|
};
|
|
75
|
-
const useStyles = () => {
|
|
73
|
+
const useStyles = ({ imageWidth = 100, imageHeight = 100 } = {}) => {
|
|
76
74
|
const { width: windowWidth } = useWindowDimensions();
|
|
77
75
|
const backgroundColor = tokens.colorNeutral7;
|
|
78
76
|
const transparentBackgroundColor = useMemo(() => colorFunction(backgroundColor).alpha(0.8).toString(), [backgroundColor]);
|
|
@@ -80,9 +78,12 @@ const useStyles = () => {
|
|
|
80
78
|
container: {
|
|
81
79
|
maxWidth: '100%',
|
|
82
80
|
},
|
|
81
|
+
imageWrapper: {
|
|
82
|
+
minWidth: 200,
|
|
83
|
+
aspectRatio: imageWidth / imageHeight,
|
|
84
|
+
},
|
|
83
85
|
image: {
|
|
84
86
|
borderRadius: 8,
|
|
85
|
-
minWidth: 200,
|
|
86
87
|
},
|
|
87
88
|
modal: {
|
|
88
89
|
flex: 1,
|
|
@@ -91,8 +92,12 @@ const useStyles = () => {
|
|
|
91
92
|
alignItems: 'center',
|
|
92
93
|
},
|
|
93
94
|
lightboxImage: {
|
|
94
|
-
width: windowWidth,
|
|
95
95
|
height: '100%',
|
|
96
|
+
width: windowWidth,
|
|
97
|
+
backgroundColor,
|
|
98
|
+
},
|
|
99
|
+
lightboxImageLoading: {
|
|
100
|
+
backgroundColor,
|
|
96
101
|
},
|
|
97
102
|
actionToolbar: {
|
|
98
103
|
width: '100%',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image_attachment.js","sourceRoot":"","sources":["../../../../src/components/conversation/attachments/image_attachment.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC7D,OAAO,EACL,KAAK,EACL,UAAU,EACV,KAAK,EACL,SAAS,EACT,mBAAmB,EACnB,YAAY,EACZ,IAAI,EACJ,OAAO,GAER,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,OAAO,EACP,eAAe,EACf,sBAAsB,GAEvB,MAAM,8BAA8B,CAAA;AACrC,OAAO,QAAQ,EAAE,EACf,OAAO,EACP,gBAAgB,EAChB,cAAc,EACd,UAAU,GAEX,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACzD,OAAO,aAAa,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAEvD,MAAM,gBAAgB,GAAG,GAAG,CAAA;AAO5B,MAAM,UAAU,eAAe,CAAC,EAC9B,UAAU,EACV,SAAS,GAIV;IACC,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAE7C,mFAAmF;IACnF,MAAM,QAAQ,GAAG,cAAc,CAAC,CAAC,CAAC,CAAA;IAClC,MAAM,OAAO,GAAG,cAAc,CAAC,CAAC,CAAC,CAAA;IAEjC,MAAM,eAAe,GAAG,WAAW,CAAC,GAAG,EAAE;QACvC,QAAQ,CAAC,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;QAC9B,OAAO,CAAC,KAAK,GAAG,UAAU,CAAC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AAc;SAC7B;QACD,qBAAqB,EAAE;YACrB,KAAK,EAAE,MAAM,CAAC,cAAc;SAC7B;QACD,YAAY,EAAE;YACZ,eAAe;YACf,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,EAAE;YACT,YAAY,EAAE,EAAE;YAChB,WAAW,EAAE,CAAC;YACd,WAAW,EAAE,MAAM,CAAC,cAAc;SACnC;QACD,gBAAgB,EAAE;YAChB,KAAK,EAAE,MAAM,CAAC,cAAc;SAC7B;KACF,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import React, { useCallback, useMemo, useState } from 'react'\nimport {\n Image,\n StyleSheet,\n Modal,\n Pressable,\n useWindowDimensions,\n SafeAreaView,\n View,\n Linking,\n ImageStyle,\n} from 'react-native'\nimport {\n Gesture,\n GestureDetector,\n GestureHandlerRootView,\n type PanGesture,\n} from 'react-native-gesture-handler'\nimport Animated, {\n runOnJS,\n useAnimatedStyle,\n useSharedValue,\n withTiming,\n type AnimatedStyle,\n} from 'react-native-reanimated'\nimport { tokens } from '../../../vendor/tapestry/tokens'\nimport { IconButton, Heading, Text } from '../../display'\nimport colorFunction from 'color'\nimport { formatDatePreview } from '../../../utils/date'\n\nconst PAN_THRESHOLD_PX = 300\n\nexport type MetaProps = {\n authorName: string\n createdAt: string\n}\n\nexport function ImageAttachment({\n attachment,\n metaProps,\n}: {\n attachment: any\n metaProps: MetaProps\n}) {\n const styles = useStyles()\n const [visible, setVisible] = useState(false)\n\n // shared values run on the native UI thread and prevents clogging up the JS thread\n const dismissY = useSharedValue(0)\n const opacity = useSharedValue(1)\n\n const resetAnimations = useCallback(() => {\n dismissY.value = withTiming(0)\n opacity.value = withTiming(1)\n }, [dismissY, opacity])\n\n const handleCloseModal = useCallback(() => {\n setVisible(false)\n resetAnimations()\n }, [setVisible, resetAnimations])\n\n const panGesture = Gesture.Pan()\n .onUpdate(e => {\n dismissY.value = e.translationY\n opacity.value = 1 - Math.abs(e.translationY) / PAN_THRESHOLD_PX\n })\n .onEnd(() => {\n runOnJS(handleCloseModal)() // Ensures we can call a JS function\n })\n\n const animatedImageStyle = useAnimatedStyle(() => ({\n transform: [{ translateY: dismissY.value }],\n opacity: opacity.value,\n }))\n\n const { attributes } = attachment\n const { url, urlMedium, filename, metadata = {} } = attributes\n const width = metadata.width || 100\n const height = metadata.height || 100\n\n return (\n <>\n <Pressable style={styles.container} onPress={() => setVisible(true)}>\n <Image\n source={{ uri: urlMedium || url }}\n style={[styles.image, { aspectRatio: width / height }]}\n accessibilityLabel={filename}\n />\n </Pressable>\n <LightboxModal\n visible={visible}\n handleCloseModal={handleCloseModal}\n uri={urlMedium || url}\n metaProps={metaProps}\n panGesture={panGesture}\n animatedImageStyle={animatedImageStyle}\n />\n </>\n )\n}\n\ninterface LightboxModalProps {\n visible: boolean\n handleCloseModal: () => void\n uri: string\n metaProps: MetaProps\n panGesture: PanGesture\n animatedImageStyle: AnimatedStyle<ImageStyle>\n}\n\nconst LightboxModal = ({\n uri,\n visible,\n handleCloseModal,\n metaProps,\n panGesture,\n animatedImageStyle,\n}: LightboxModalProps) => {\n const styles = useStyles()\n\n const { authorName, createdAt } = metaProps\n\n const handleOpenInBrowser = () => {\n Linking.openURL(uri)\n }\n\n return (\n <Modal visible={visible} transparent animationType=\"fade\" onRequestClose={handleCloseModal}>\n <SafeAreaView style={styles.modal}>\n <GestureHandlerRootView>\n <GestureDetector gesture={panGesture}>\n <Animated.Image\n source={{ uri }}\n style={[styles.lightboxImage, animatedImageStyle]}\n resizeMode=\"contain\"\n />\n </GestureDetector>\n <View style={styles.actionToolbar} accessibilityRole=\"toolbar\">\n <View style={styles.actionToolbarTextMeta}>\n <Heading variant=\"h3\" style={styles.actionToolbarTitle} numberOfLines={1}>\n {authorName}\n </Heading>\n <Text variant=\"tertiary\" style={styles.actionToolbarSubtitle}>\n {formatDatePreview(createdAt)}\n </Text>\n </View>\n <IconButton\n onPress={handleOpenInBrowser}\n name=\"general.newWindow\"\n accessibilityRole=\"link\"\n accessibilityLabel=\"Open image in browser\"\n accessibilityHint=\"Image can be downloaded and shared through the browser.\"\n style={styles.actionButton}\n iconStyle={styles.actionButtonIcon}\n size=\"lg\"\n />\n <IconButton\n onPress={handleCloseModal}\n name=\"general.x\"\n accessibilityLabel=\"Close image\"\n style={styles.actionButton}\n iconStyle={styles.actionButtonIcon}\n />\n </View>\n </GestureHandlerRootView>\n </SafeAreaView>\n </Modal>\n )\n}\n\nconst useStyles = () => {\n const { width: windowWidth } = useWindowDimensions()\n const backgroundColor = tokens.colorNeutral7\n const transparentBackgroundColor = useMemo(\n () => colorFunction(backgroundColor).alpha(0.8).toString(),\n [backgroundColor]\n )\n\n return StyleSheet.create({\n container: {\n maxWidth: '100%',\n },\n image: {\n borderRadius: 8,\n minWidth: 200,\n },\n modal: {\n flex: 1,\n backgroundColor,\n justifyContent: 'center',\n alignItems: 'center',\n },\n lightboxImage: {\n width: windowWidth,\n height: '100%',\n },\n actionToolbar: {\n width: '100%',\n position: 'absolute',\n top: 0,\n flexDirection: 'row',\n alignItems: 'center',\n gap: 20,\n paddingHorizontal: 16,\n paddingTop: 16,\n paddingBottom: 8,\n backgroundColor: transparentBackgroundColor,\n },\n actionToolbarTextMeta: {\n flex: 1,\n },\n actionToolbarTitle: {\n marginRight: 'auto',\n flexShrink: 1,\n color: tokens.colorNeutral88,\n },\n actionToolbarSubtitle: {\n color: tokens.colorNeutral68,\n },\n actionButton: {\n backgroundColor,\n height: 40,\n width: 40,\n borderRadius: 50,\n borderWidth: 1,\n borderColor: tokens.colorNeutral24,\n },\n actionButtonIcon: {\n color: tokens.colorNeutral88,\n },\n })\n}\n"]}
|
|
1
|
+
{"version":3,"file":"image_attachment.js","sourceRoot":"","sources":["../../../../src/components/conversation/attachments/image_attachment.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC7D,OAAO,EACL,UAAU,EACV,KAAK,EACL,SAAS,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AqB,EAAE;YACrB,KAAK,EAAE,MAAM,CAAC,cAAc;SAC7B;QACD,YAAY,EAAE;YACZ,eAAe;YACf,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,EAAE;YACT,YAAY,EAAE,EAAE;YAChB,WAAW,EAAE,CAAC;YACd,WAAW,EAAE,MAAM,CAAC,cAAc;SACnC;QACD,gBAAgB,EAAE;YAChB,KAAK,EAAE,MAAM,CAAC,cAAc;SAC7B;KACF,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import React, { useCallback, useMemo, useState } from 'react'\nimport {\n StyleSheet,\n Modal,\n Pressable,\n useWindowDimensions,\n SafeAreaView,\n View,\n Linking,\n ImageStyle,\n} from 'react-native'\nimport {\n Gesture,\n GestureDetector,\n GestureHandlerRootView,\n type PanGesture,\n} from 'react-native-gesture-handler'\nimport {\n runOnJS,\n useAnimatedStyle,\n useSharedValue,\n withTiming,\n type AnimatedStyle,\n} from 'react-native-reanimated'\nimport { tokens } from '../../../vendor/tapestry/tokens'\nimport { IconButton, Image, Heading, Text } from '../../display'\nimport colorFunction from 'color'\nimport { formatDatePreview } from '../../../utils/date'\n\nconst PAN_THRESHOLD_PX = 300\n\nexport type MetaProps = {\n authorName: string\n createdAt: string\n}\n\nexport function ImageAttachment({\n attachment,\n metaProps,\n}: {\n attachment: any\n metaProps: MetaProps\n}) {\n const { attributes } = attachment\n const { url, urlMedium, filename, metadata = {} } = attributes\n\n const styles = useStyles({ imageWidth: metadata.width, imageHeight: metadata.height })\n const [visible, setVisible] = useState(false)\n\n // shared values run on the native UI thread and prevents clogging up the JS thread\n const dismissY = useSharedValue(0)\n const opacity = useSharedValue(1)\n\n const resetAnimations = useCallback(() => {\n dismissY.value = withTiming(0)\n opacity.value = withTiming(1)\n }, [dismissY, opacity])\n\n const handleCloseModal = useCallback(() => {\n setVisible(false)\n resetAnimations()\n }, [setVisible, resetAnimations])\n\n const panGesture = Gesture.Pan()\n .onUpdate(e => {\n dismissY.value = e.translationY\n opacity.value = 1 - Math.abs(e.translationY) / PAN_THRESHOLD_PX\n })\n .onEnd(() => {\n runOnJS(handleCloseModal)() // Ensures we can call a JS function\n })\n\n const animatedImageStyle = useAnimatedStyle(() => ({\n transform: [{ translateY: dismissY.value }],\n opacity: opacity.value,\n }))\n\n return (\n <>\n <Pressable style={styles.container} onPress={() => setVisible(true)}>\n <Image\n source={{ uri: urlMedium || url }}\n style={{ borderRadius: 8 }}\n wrapperStyle={styles.imageWrapper}\n alt={filename}\n />\n </Pressable>\n <LightboxModal\n visible={visible}\n handleCloseModal={handleCloseModal}\n uri={urlMedium || url}\n metaProps={metaProps}\n panGesture={panGesture}\n animatedImageStyle={animatedImageStyle}\n />\n </>\n )\n}\n\ninterface LightboxModalProps {\n visible: boolean\n handleCloseModal: () => void\n uri: string\n metaProps: MetaProps\n panGesture: PanGesture\n animatedImageStyle: AnimatedStyle<ImageStyle>\n}\n\nconst LightboxModal = ({\n uri,\n visible,\n handleCloseModal,\n metaProps,\n panGesture,\n animatedImageStyle,\n}: LightboxModalProps) => {\n const styles = useStyles()\n\n const { authorName, createdAt } = metaProps\n\n const handleOpenInBrowser = () => {\n Linking.openURL(uri)\n }\n\n return (\n <Modal visible={visible} transparent animationType=\"fade\" onRequestClose={handleCloseModal}>\n <SafeAreaView style={styles.modal}>\n <GestureHandlerRootView>\n <GestureDetector gesture={panGesture}>\n <Image\n source={{ uri }}\n loadingBackgroundStyles={styles.lightboxImageLoading}\n style={styles.lightboxImage}\n animatedImageStyle={animatedImageStyle}\n resizeMode=\"contain\"\n animated={true}\n alt=\"\"\n />\n </GestureDetector>\n <View style={styles.actionToolbar} accessibilityRole=\"toolbar\">\n <View style={styles.actionToolbarTextMeta}>\n <Heading variant=\"h3\" style={styles.actionToolbarTitle} numberOfLines={1}>\n {authorName}\n </Heading>\n <Text variant=\"tertiary\" style={styles.actionToolbarSubtitle}>\n {formatDatePreview(createdAt)}\n </Text>\n </View>\n <IconButton\n onPress={handleOpenInBrowser}\n name=\"general.newWindow\"\n accessibilityRole=\"link\"\n accessibilityLabel=\"Open image in browser\"\n accessibilityHint=\"Image can be downloaded and shared through the browser.\"\n style={styles.actionButton}\n iconStyle={styles.actionButtonIcon}\n size=\"lg\"\n />\n <IconButton\n onPress={handleCloseModal}\n name=\"general.x\"\n accessibilityLabel=\"Close image\"\n style={styles.actionButton}\n iconStyle={styles.actionButtonIcon}\n />\n </View>\n </GestureHandlerRootView>\n </SafeAreaView>\n </Modal>\n )\n}\n\ninterface UseStylesProps {\n imageWidth?: number\n imageHeight?: number\n}\n\nconst useStyles = ({ imageWidth = 100, imageHeight = 100 }: UseStylesProps = {}) => {\n const { width: windowWidth } = useWindowDimensions()\n const backgroundColor = tokens.colorNeutral7\n const transparentBackgroundColor = useMemo(\n () => colorFunction(backgroundColor).alpha(0.8).toString(),\n [backgroundColor]\n )\n\n return StyleSheet.create({\n container: {\n maxWidth: '100%',\n },\n imageWrapper: {\n minWidth: 200,\n aspectRatio: imageWidth / imageHeight,\n },\n image: {\n borderRadius: 8,\n },\n modal: {\n flex: 1,\n backgroundColor,\n justifyContent: 'center',\n alignItems: 'center',\n },\n lightboxImage: {\n height: '100%',\n width: windowWidth,\n backgroundColor,\n },\n lightboxImageLoading: {\n backgroundColor,\n },\n actionToolbar: {\n width: '100%',\n position: 'absolute',\n top: 0,\n flexDirection: 'row',\n alignItems: 'center',\n gap: 20,\n paddingHorizontal: 16,\n paddingTop: 16,\n paddingBottom: 8,\n backgroundColor: transparentBackgroundColor,\n },\n actionToolbarTextMeta: {\n flex: 1,\n },\n actionToolbarTitle: {\n marginRight: 'auto',\n flexShrink: 1,\n color: tokens.colorNeutral88,\n },\n actionToolbarSubtitle: {\n color: tokens.colorNeutral68,\n },\n actionButton: {\n backgroundColor,\n height: 40,\n width: 40,\n borderRadius: 50,\n borderWidth: 1,\n borderColor: tokens.colorNeutral24,\n },\n actionButtonIcon: {\n color: tokens.colorNeutral88,\n },\n })\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ImageProps as ReactNativeImageProps, ViewStyle } from 'react-native';
|
|
2
|
+
import { ImageStyle, ImageProps as ReactNativeImageProps, ViewStyle } from 'react-native';
|
|
3
|
+
import { AnimatedStyle } from 'react-native-reanimated';
|
|
3
4
|
export interface ImageProps extends ReactNativeImageProps {
|
|
4
5
|
/**
|
|
5
6
|
* Describes the image to screen-readers and marks the image as `accessible`.
|
|
@@ -26,6 +27,14 @@ export interface ImageProps extends ReactNativeImageProps {
|
|
|
26
27
|
* Style the outer View of the image.
|
|
27
28
|
*/
|
|
28
29
|
wrapperStyle?: ViewStyle;
|
|
30
|
+
/**
|
|
31
|
+
* Changes the underlying image component to Animated.Image.
|
|
32
|
+
*/
|
|
33
|
+
animated?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Style the image if animated.
|
|
36
|
+
*/
|
|
37
|
+
animatedImageStyle?: AnimatedStyle<ImageStyle>;
|
|
29
38
|
}
|
|
30
|
-
export declare function Image({ source, onLoad, defaultLoading, loadingEnabled, loaderSize, loadingBackgroundStyles, style, wrapperStyle, alt, ...props }: ImageProps): React.JSX.Element;
|
|
39
|
+
export declare function Image({ source, onLoad, defaultLoading, loadingEnabled, loaderSize, loadingBackgroundStyles, style, wrapperStyle, alt, animated, animatedImageStyle, ...props }: ImageProps): React.JSX.Element;
|
|
31
40
|
//# sourceMappingURL=image.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../../src/components/display/image.tsx"],"names":[],"mappings":"AACA,OAAO,KAAmB,MAAM,OAAO,CAAA;AACvC,OAAO,
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../../src/components/display/image.tsx"],"names":[],"mappings":"AACA,OAAO,KAAmB,MAAM,OAAO,CAAA;AACvC,OAAO,EAGL,UAAU,EAEV,UAAU,IAAI,qBAAqB,EAGnC,SAAS,EACV,MAAM,cAAc,CAAA;AACrB,OAAiB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAQjE,MAAM,WAAW,UAAW,SAAQ,qBAAqB;IACvD;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,uBAAuB,CAAC,EAAE,SAAS,CAAA;IACnC;;OAEG;IACH,YAAY,CAAC,EAAE,SAAS,CAAA;IACxB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;OAEG;IACH,kBAAkB,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAA;CAC/C;AAED,wBAAgB,KAAK,CAAC,EACpB,MAAM,EACN,MAAa,EACb,cAAqB,EACrB,cAAqB,EACrB,UAAe,EACf,uBAAuB,EACvB,KAAU,EACV,YAAiB,EACjB,GAAG,EACH,QAAgB,EAChB,kBAAuB,EACvB,GAAG,KAAK,EACT,EAAE,UAAU,qBAoCZ"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { noop } from 'lodash';
|
|
2
2
|
import React, { useState } from 'react';
|
|
3
3
|
import { Image as ReactNativeImage, StyleSheet, View, } from 'react-native';
|
|
4
|
+
import Animated from 'react-native-reanimated';
|
|
4
5
|
import { useTheme } from '../../hooks';
|
|
5
6
|
import { Spinner } from './spinner';
|
|
6
|
-
export function Image({ source, onLoad = noop, defaultLoading = true, loadingEnabled = true, loaderSize = 24, loadingBackgroundStyles, style = {}, wrapperStyle = {}, alt, ...props }) {
|
|
7
|
+
export function Image({ source, onLoad = noop, defaultLoading = true, loadingEnabled = true, loaderSize = 24, loadingBackgroundStyles, style = {}, wrapperStyle = {}, alt, animated = false, animatedImageStyle = {}, ...props }) {
|
|
7
8
|
const [loading, setLoading] = useState(defaultLoading);
|
|
8
9
|
const imageStyles = StyleSheet.flatten(style);
|
|
9
10
|
const { width = '100%', height = '100%', borderRadius = 0 } = imageStyles || {};
|
|
@@ -12,8 +13,9 @@ export function Image({ source, onLoad = noop, defaultLoading = true, loadingEna
|
|
|
12
13
|
setLoading(false);
|
|
13
14
|
onLoad?.(event);
|
|
14
15
|
};
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
const ImageComponent = animated || animatedImageStyle ? Animated.Image : ReactNativeImage;
|
|
17
|
+
return (<View style={wrapperStyle} accessible={Boolean(alt)} accessibilityRole="image" accessibilityState={{ busy: loading }} collapsable={false}>
|
|
18
|
+
<ImageComponent style={[styles.image, imageStyles, animatedImageStyle]} onLoad={handleOnLoad} source={source} alt={loading ? '' : alt} {...props}/>
|
|
17
19
|
{loading && loadingEnabled && (<View style={[styles.loadingBackground, loadingBackgroundStyles]}>
|
|
18
20
|
<Spinner size={loaderSize}/>
|
|
19
21
|
</View>)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../../src/components/display/image.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACvC,OAAO,
|
|
1
|
+
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../../src/components/display/image.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACvC,OAAO,EAIL,KAAK,IAAI,gBAAgB,EAEzB,UAAU,EACV,IAAI,GAEL,MAAM,cAAc,CAAA;AACrB,OAAO,QAA2B,MAAM,yBAAyB,CAAA;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AA0CnC,MAAM,U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AC,CAAC,CACvD,MAAM,CAAC,CAAC,YAAY,CAAC,CACrB,MAAM,CAAC,CAAC,MAAM,CAAC,CACf,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CACxB,IAAI,KAAK,CAAC,EAEZ;MAAA,CAAC,OAAO,IAAI,cAAc,IAAI,CAC5B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,iBAAiB,EAAE,uBAAuB,CAAC,CAAC,CAC/D;UAAA,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,EAC5B;QAAA,EAAE,IAAI,CAAC,CACR,CACH;IAAA,EAAE,IAAI,CAAC,CACR,CAAA;AACH,CAAC;AAYD,MAAM,SAAS,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAU,EAAE,EAAE;IAC5D,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAA;IAE7B,OAAO,UAAU,CAAC,MAAM,CAAC;QACvB,iBAAiB,EAAE;YACjB,QAAQ,EAAE,UAAU;YACpB,GAAG,EAAE,CAAC;YACN,IAAI,EAAE,CAAC;YACP,eAAe,EAAE,MAAM,CAAC,mBAAmB;YAC3C,YAAY;YACZ,KAAK;YACL,MAAM;SACP;QACD,KAAK,EAAE;YACL,eAAe,EAAE,MAAM,CAAC,mBAAmB;YAC3C,KAAK;YACL,MAAM;SACP;KACF,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import { noop } from 'lodash'\nimport React, { useState } from 'react'\nimport {\n AnimatableNumericValue,\n DimensionValue,\n ImageStyle,\n Image as ReactNativeImage,\n ImageProps as ReactNativeImageProps,\n StyleSheet,\n View,\n ViewStyle,\n} from 'react-native'\nimport Animated, { AnimatedStyle } from 'react-native-reanimated'\nimport { useTheme } from '../../hooks'\nimport { Spinner } from './spinner'\n\n// =================================\n// ====== Component ================\n// =================================\n\nexport interface ImageProps extends ReactNativeImageProps {\n /**\n * Describes the image to screen-readers and marks the image as `accessible`.\n * Passing an empty string will hide the image from screen-readers.\n */\n alt: string\n /**\n * Shows the image's loading spinner right away. Enabled by default.\n */\n defaultLoading?: boolean\n /**\n * Turn on or off loading spinner.\n */\n loadingEnabled?: boolean\n /**\n * Size of the loading spinner.\n */\n loaderSize?: number\n /**\n * Style object for the preload background.\n */\n loadingBackgroundStyles?: ViewStyle\n /**\n * Style the outer View of the image.\n */\n wrapperStyle?: ViewStyle\n /**\n * Changes the underlying image component to Animated.Image.\n */\n animated?: boolean\n /**\n * Style the image if animated.\n */\n animatedImageStyle?: AnimatedStyle<ImageStyle>\n}\n\nexport function Image({\n source,\n onLoad = noop,\n defaultLoading = true,\n loadingEnabled = true,\n loaderSize = 24,\n loadingBackgroundStyles,\n style = {},\n wrapperStyle = {},\n alt,\n animated = false,\n animatedImageStyle = {},\n ...props\n}: ImageProps) {\n const [loading, setLoading] = useState(defaultLoading)\n\n const imageStyles = StyleSheet.flatten(style)\n const { width = '100%', height = '100%', borderRadius = 0 } = imageStyles || {}\n const styles = useStyles({ width, height, borderRadius })\n\n const handleOnLoad = (event: any) => {\n setLoading(false)\n onLoad?.(event)\n }\n\n const ImageComponent = animated || animatedImageStyle ? Animated.Image : ReactNativeImage\n\n return (\n <View\n style={wrapperStyle}\n accessible={Boolean(alt)}\n accessibilityRole=\"image\"\n accessibilityState={{ busy: loading }}\n collapsable={false}\n >\n <ImageComponent\n style={[styles.image, imageStyles, animatedImageStyle]}\n onLoad={handleOnLoad}\n source={source}\n alt={loading ? '' : alt}\n {...props}\n />\n {loading && loadingEnabled && (\n <View style={[styles.loadingBackground, loadingBackgroundStyles]}>\n <Spinner size={loaderSize} />\n </View>\n )}\n </View>\n )\n}\n\n// =================================\n// ====== Styles ===================\n// =================================\n\ninterface Styles {\n width: DimensionValue\n height: DimensionValue\n borderRadius: AnimatableNumericValue | string\n}\n\nconst useStyles = ({ width, height, borderRadius }: Styles) => {\n const { colors } = useTheme()\n\n return StyleSheet.create({\n loadingBackground: {\n position: 'absolute',\n top: 0,\n left: 0,\n backgroundColor: colors.fillColorNeutral070,\n borderRadius,\n width,\n height,\n },\n image: {\n backgroundColor: colors.fillColorNeutral070,\n width,\n height,\n },\n })\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/chat-react-native",
|
|
3
|
-
"version": "3.4.1-rc.
|
|
3
|
+
"version": "3.4.1-rc.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"prettier": "^3.4.2",
|
|
55
55
|
"typescript": "<5.6.0"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "02b089f3e6e553fe5d3b5ce141615f8a6d834676"
|
|
58
58
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React, { useCallback, useMemo, useState } from 'react'
|
|
2
2
|
import {
|
|
3
|
-
Image,
|
|
4
3
|
StyleSheet,
|
|
5
4
|
Modal,
|
|
6
5
|
Pressable,
|
|
@@ -16,7 +15,7 @@ import {
|
|
|
16
15
|
GestureHandlerRootView,
|
|
17
16
|
type PanGesture,
|
|
18
17
|
} from 'react-native-gesture-handler'
|
|
19
|
-
import
|
|
18
|
+
import {
|
|
20
19
|
runOnJS,
|
|
21
20
|
useAnimatedStyle,
|
|
22
21
|
useSharedValue,
|
|
@@ -24,7 +23,7 @@ import Animated, {
|
|
|
24
23
|
type AnimatedStyle,
|
|
25
24
|
} from 'react-native-reanimated'
|
|
26
25
|
import { tokens } from '../../../vendor/tapestry/tokens'
|
|
27
|
-
import { IconButton, Heading, Text } from '../../display'
|
|
26
|
+
import { IconButton, Image, Heading, Text } from '../../display'
|
|
28
27
|
import colorFunction from 'color'
|
|
29
28
|
import { formatDatePreview } from '../../../utils/date'
|
|
30
29
|
|
|
@@ -42,7 +41,10 @@ export function ImageAttachment({
|
|
|
42
41
|
attachment: any
|
|
43
42
|
metaProps: MetaProps
|
|
44
43
|
}) {
|
|
45
|
-
const
|
|
44
|
+
const { attributes } = attachment
|
|
45
|
+
const { url, urlMedium, filename, metadata = {} } = attributes
|
|
46
|
+
|
|
47
|
+
const styles = useStyles({ imageWidth: metadata.width, imageHeight: metadata.height })
|
|
46
48
|
const [visible, setVisible] = useState(false)
|
|
47
49
|
|
|
48
50
|
// shared values run on the native UI thread and prevents clogging up the JS thread
|
|
@@ -73,18 +75,14 @@ export function ImageAttachment({
|
|
|
73
75
|
opacity: opacity.value,
|
|
74
76
|
}))
|
|
75
77
|
|
|
76
|
-
const { attributes } = attachment
|
|
77
|
-
const { url, urlMedium, filename, metadata = {} } = attributes
|
|
78
|
-
const width = metadata.width || 100
|
|
79
|
-
const height = metadata.height || 100
|
|
80
|
-
|
|
81
78
|
return (
|
|
82
79
|
<>
|
|
83
80
|
<Pressable style={styles.container} onPress={() => setVisible(true)}>
|
|
84
81
|
<Image
|
|
85
82
|
source={{ uri: urlMedium || url }}
|
|
86
|
-
style={
|
|
87
|
-
|
|
83
|
+
style={{ borderRadius: 8 }}
|
|
84
|
+
wrapperStyle={styles.imageWrapper}
|
|
85
|
+
alt={filename}
|
|
88
86
|
/>
|
|
89
87
|
</Pressable>
|
|
90
88
|
<LightboxModal
|
|
@@ -129,10 +127,14 @@ const LightboxModal = ({
|
|
|
129
127
|
<SafeAreaView style={styles.modal}>
|
|
130
128
|
<GestureHandlerRootView>
|
|
131
129
|
<GestureDetector gesture={panGesture}>
|
|
132
|
-
<
|
|
130
|
+
<Image
|
|
133
131
|
source={{ uri }}
|
|
134
|
-
|
|
132
|
+
loadingBackgroundStyles={styles.lightboxImageLoading}
|
|
133
|
+
style={styles.lightboxImage}
|
|
134
|
+
animatedImageStyle={animatedImageStyle}
|
|
135
135
|
resizeMode="contain"
|
|
136
|
+
animated={true}
|
|
137
|
+
alt=""
|
|
136
138
|
/>
|
|
137
139
|
</GestureDetector>
|
|
138
140
|
<View style={styles.actionToolbar} accessibilityRole="toolbar">
|
|
@@ -168,7 +170,12 @@ const LightboxModal = ({
|
|
|
168
170
|
)
|
|
169
171
|
}
|
|
170
172
|
|
|
171
|
-
|
|
173
|
+
interface UseStylesProps {
|
|
174
|
+
imageWidth?: number
|
|
175
|
+
imageHeight?: number
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const useStyles = ({ imageWidth = 100, imageHeight = 100 }: UseStylesProps = {}) => {
|
|
172
179
|
const { width: windowWidth } = useWindowDimensions()
|
|
173
180
|
const backgroundColor = tokens.colorNeutral7
|
|
174
181
|
const transparentBackgroundColor = useMemo(
|
|
@@ -180,9 +187,12 @@ const useStyles = () => {
|
|
|
180
187
|
container: {
|
|
181
188
|
maxWidth: '100%',
|
|
182
189
|
},
|
|
190
|
+
imageWrapper: {
|
|
191
|
+
minWidth: 200,
|
|
192
|
+
aspectRatio: imageWidth / imageHeight,
|
|
193
|
+
},
|
|
183
194
|
image: {
|
|
184
195
|
borderRadius: 8,
|
|
185
|
-
minWidth: 200,
|
|
186
196
|
},
|
|
187
197
|
modal: {
|
|
188
198
|
flex: 1,
|
|
@@ -191,8 +201,12 @@ const useStyles = () => {
|
|
|
191
201
|
alignItems: 'center',
|
|
192
202
|
},
|
|
193
203
|
lightboxImage: {
|
|
194
|
-
width: windowWidth,
|
|
195
204
|
height: '100%',
|
|
205
|
+
width: windowWidth,
|
|
206
|
+
backgroundColor,
|
|
207
|
+
},
|
|
208
|
+
lightboxImageLoading: {
|
|
209
|
+
backgroundColor,
|
|
196
210
|
},
|
|
197
211
|
actionToolbar: {
|
|
198
212
|
width: '100%',
|
|
@@ -3,12 +3,14 @@ import React, { useState } from 'react'
|
|
|
3
3
|
import {
|
|
4
4
|
AnimatableNumericValue,
|
|
5
5
|
DimensionValue,
|
|
6
|
+
ImageStyle,
|
|
6
7
|
Image as ReactNativeImage,
|
|
7
8
|
ImageProps as ReactNativeImageProps,
|
|
8
9
|
StyleSheet,
|
|
9
10
|
View,
|
|
10
11
|
ViewStyle,
|
|
11
12
|
} from 'react-native'
|
|
13
|
+
import Animated, { AnimatedStyle } from 'react-native-reanimated'
|
|
12
14
|
import { useTheme } from '../../hooks'
|
|
13
15
|
import { Spinner } from './spinner'
|
|
14
16
|
|
|
@@ -42,6 +44,14 @@ export interface ImageProps extends ReactNativeImageProps {
|
|
|
42
44
|
* Style the outer View of the image.
|
|
43
45
|
*/
|
|
44
46
|
wrapperStyle?: ViewStyle
|
|
47
|
+
/**
|
|
48
|
+
* Changes the underlying image component to Animated.Image.
|
|
49
|
+
*/
|
|
50
|
+
animated?: boolean
|
|
51
|
+
/**
|
|
52
|
+
* Style the image if animated.
|
|
53
|
+
*/
|
|
54
|
+
animatedImageStyle?: AnimatedStyle<ImageStyle>
|
|
45
55
|
}
|
|
46
56
|
|
|
47
57
|
export function Image({
|
|
@@ -54,6 +64,8 @@ export function Image({
|
|
|
54
64
|
style = {},
|
|
55
65
|
wrapperStyle = {},
|
|
56
66
|
alt,
|
|
67
|
+
animated = false,
|
|
68
|
+
animatedImageStyle = {},
|
|
57
69
|
...props
|
|
58
70
|
}: ImageProps) {
|
|
59
71
|
const [loading, setLoading] = useState(defaultLoading)
|
|
@@ -67,15 +79,18 @@ export function Image({
|
|
|
67
79
|
onLoad?.(event)
|
|
68
80
|
}
|
|
69
81
|
|
|
82
|
+
const ImageComponent = animated || animatedImageStyle ? Animated.Image : ReactNativeImage
|
|
83
|
+
|
|
70
84
|
return (
|
|
71
85
|
<View
|
|
72
86
|
style={wrapperStyle}
|
|
73
87
|
accessible={Boolean(alt)}
|
|
74
88
|
accessibilityRole="image"
|
|
75
89
|
accessibilityState={{ busy: loading }}
|
|
90
|
+
collapsable={false}
|
|
76
91
|
>
|
|
77
|
-
<
|
|
78
|
-
style={[styles.image, imageStyles]}
|
|
92
|
+
<ImageComponent
|
|
93
|
+
style={[styles.image, imageStyles, animatedImageStyle]}
|
|
79
94
|
onLoad={handleOnLoad}
|
|
80
95
|
source={source}
|
|
81
96
|
alt={loading ? '' : alt}
|