@planningcenter/chat-react-native 4.8.0-rc.11 → 4.8.0-rc.13

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.
@@ -1,6 +1,12 @@
1
1
  import React from 'react'
2
- import { StyleSheet } from 'react-native'
2
+ import { StyleSheet, View } from 'react-native'
3
3
  import { Pressable, type PressableProps } from 'react-native-gesture-handler'
4
+ import Animated, {
5
+ Extrapolation,
6
+ SharedValue,
7
+ interpolate,
8
+ useAnimatedStyle,
9
+ } from 'react-native-reanimated'
4
10
  import { useCreateAndroidRippleColor, useTheme } from '../../hooks'
5
11
  import { Haptic } from '../../utils/native_adapters/configuration'
6
12
  import {
@@ -11,8 +17,12 @@ import {
11
17
  import { tokens } from '../../vendor/tapestry/tokens'
12
18
  import { Icon, IconString, Spinner, Text } from '../display'
13
19
 
20
+ export const SWIPEABLE_TOGGLE_BUTTON_WIDTH = 120
21
+
14
22
  interface SwipeableToggleButtonProps extends PressableProps {
15
23
  backgroundColor: string
24
+ /** How far the swipe is open, 0 (closed) to 1 (fully open). */
25
+ progress: SharedValue<number>
16
26
  toggled: boolean
17
27
  toggleContent: {
18
28
  true: { iconName: IconString; label: string }
@@ -24,6 +34,7 @@ interface SwipeableToggleButtonProps extends PressableProps {
24
34
  export function SwipeableToggleButton({
25
35
  backgroundColor,
26
36
  onPress,
37
+ progress,
27
38
  toggleContent,
28
39
  disabled = false,
29
40
  toggled,
@@ -37,6 +48,13 @@ export function SwipeableToggleButton({
37
48
 
38
49
  const { iconName, label } = toggleContent[toggled ? 'true' : 'false']
39
50
 
51
+ const iconStyle = useAnimatedStyle(() => ({
52
+ transform: [{ scale: interpolate(progress.value, [0, 1], [0.7, 1], Extrapolation.CLAMP) }],
53
+ }))
54
+ const labelStyle = useAnimatedStyle(() => ({
55
+ opacity: interpolate(progress.value, [0.5, 1], [0, 1], Extrapolation.CLAMP),
56
+ }))
57
+
40
58
  return (
41
59
  <Pressable
42
60
  onPress={event => {
@@ -53,20 +71,24 @@ export function SwipeableToggleButton({
53
71
  {loading ? (
54
72
  <Spinner size={20} />
55
73
  ) : (
56
- <>
57
- <Icon
58
- name={iconName}
59
- style={styles.icon}
60
- maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER}
61
- />
62
- <Text
63
- variant="footnote"
64
- style={styles.text}
65
- maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER}
66
- >
67
- {label}
68
- </Text>
69
- </>
74
+ <View style={styles.content}>
75
+ <Animated.View style={iconStyle}>
76
+ <Icon
77
+ name={iconName}
78
+ style={styles.icon}
79
+ maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER}
80
+ />
81
+ </Animated.View>
82
+ <Animated.View style={labelStyle}>
83
+ <Text
84
+ variant="footnote"
85
+ style={styles.text}
86
+ maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER}
87
+ >
88
+ {label}
89
+ </Text>
90
+ </Animated.View>
91
+ </View>
70
92
  )}
71
93
  </Pressable>
72
94
  )
@@ -85,10 +107,17 @@ const useStyles = ({ backgroundColor, disabled }: Partial<SwipeableToggleButtonP
85
107
  flexDirection: 'column',
86
108
  alignItems: 'center',
87
109
  justifyContent: 'center',
88
- gap: 4,
89
110
  height: '100%',
111
+ overflow: 'hidden',
90
112
  backgroundColor: buttonBackgroundColor,
91
113
  },
114
+ // Laid out at the fully open width and clipped by the button, so the icon and label stay
115
+ // centered and never reflow while the button is narrower than that.
116
+ content: {
117
+ width: SWIPEABLE_TOGGLE_BUTTON_WIDTH,
118
+ alignItems: 'center',
119
+ gap: 4,
120
+ },
92
121
  icon: {
93
122
  fontSize: 20,
94
123
  color: fillColor,