@idealyst/components 1.2.137 → 1.2.139
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idealyst/components",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.139",
|
|
4
4
|
"description": "Shared component library for React and React Native",
|
|
5
5
|
"documentation": "https://github.com/IdealystIO/idealyst-framework/tree/main/packages/components#readme",
|
|
6
6
|
"readme": "README.md",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"publish:npm": "npm publish"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@idealyst/theme": "^1.2.
|
|
59
|
+
"@idealyst/theme": "^1.2.139",
|
|
60
60
|
"@mdi/js": ">=7.0.0",
|
|
61
61
|
"@mdi/react": ">=1.0.0",
|
|
62
62
|
"@react-native-vector-icons/common": ">=12.0.0",
|
|
@@ -111,8 +111,8 @@
|
|
|
111
111
|
},
|
|
112
112
|
"devDependencies": {
|
|
113
113
|
"@idealyst/blur": "^1.2.40",
|
|
114
|
-
"@idealyst/theme": "^1.2.
|
|
115
|
-
"@idealyst/tooling": "^1.2.
|
|
114
|
+
"@idealyst/theme": "^1.2.139",
|
|
115
|
+
"@idealyst/tooling": "^1.2.139",
|
|
116
116
|
"@mdi/react": "^1.6.1",
|
|
117
117
|
"@types/react": "^19.1.0",
|
|
118
118
|
"react": "^19.1.0",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useEffect, forwardRef, useMemo
|
|
1
|
+
import { useEffect, forwardRef, useMemo } from 'react';
|
|
2
2
|
import { Modal, View, Text, TouchableOpacity, TouchableWithoutFeedback, BackHandler, Platform, Keyboard, useWindowDimensions } from 'react-native';
|
|
3
|
-
import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing } from 'react-native-reanimated';
|
|
3
|
+
import Animated, { useSharedValue, useDerivedValue, useAnimatedStyle, withTiming, Easing } from 'react-native-reanimated';
|
|
4
4
|
import { useSafeAreaInsets } from '@idealyst/theme';
|
|
5
5
|
import { DialogProps } from './types';
|
|
6
6
|
import { dialogStyles } from './Dialog.styles';
|
|
@@ -51,27 +51,35 @@ const Dialog = forwardRef<View, DialogProps>(({
|
|
|
51
51
|
// Get safe area insets
|
|
52
52
|
const insets = useSafeAreaInsets();
|
|
53
53
|
|
|
54
|
-
//
|
|
55
|
-
const
|
|
54
|
+
// Animated keyboard height for smooth keyboard avoidance
|
|
55
|
+
const keyboardHeight = useSharedValue(0);
|
|
56
56
|
const { height: screenHeight } = useWindowDimensions();
|
|
57
57
|
|
|
58
58
|
useEffect(() => {
|
|
59
|
-
if (!avoidKeyboard || !open)
|
|
59
|
+
if (!avoidKeyboard || !open) {
|
|
60
|
+
// Animate back to 0 when dialog closes or avoidKeyboard is disabled
|
|
61
|
+
keyboardHeight.value = withTiming(0, { duration: 250 });
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
60
64
|
|
|
61
65
|
const showEvent = Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow';
|
|
62
66
|
const hideEvent = Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide';
|
|
63
67
|
|
|
64
68
|
const showSub = Keyboard.addListener(showEvent, (e) => {
|
|
65
|
-
|
|
69
|
+
const duration = Platform.OS === 'ios' ? e.duration : 250;
|
|
70
|
+
keyboardHeight.value = withTiming(e.endCoordinates.height, { duration });
|
|
66
71
|
});
|
|
67
72
|
|
|
68
|
-
const hideSub = Keyboard.addListener(hideEvent, () => {
|
|
69
|
-
|
|
73
|
+
const hideSub = Keyboard.addListener(hideEvent, (e) => {
|
|
74
|
+
const duration = Platform.OS === 'ios' ? (e?.duration ?? 250) : 250;
|
|
75
|
+
keyboardHeight.value = withTiming(0, { duration });
|
|
70
76
|
});
|
|
71
77
|
|
|
72
78
|
return () => {
|
|
73
79
|
showSub.remove();
|
|
74
80
|
hideSub.remove();
|
|
81
|
+
// Animate back to 0 on cleanup so we don't get stuck at a stale value
|
|
82
|
+
keyboardHeight.value = withTiming(0, { duration: 250 });
|
|
75
83
|
};
|
|
76
84
|
}, [avoidKeyboard, open]);
|
|
77
85
|
|
|
@@ -168,48 +176,69 @@ const Dialog = forwardRef<View, DialogProps>(({
|
|
|
168
176
|
bottom: 0,
|
|
169
177
|
};
|
|
170
178
|
|
|
171
|
-
//
|
|
172
|
-
// Top: always safe area + padding
|
|
173
|
-
// Bottom: safe area + padding (no keyboard) or keyboard + padding (with keyboard)
|
|
179
|
+
// Derived bottom offset — animates smoothly with keyboard
|
|
174
180
|
const topOffset = insets.top + paddingProp;
|
|
175
|
-
const bottomOffset =
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
+
const bottomOffset = useDerivedValue(() => {
|
|
182
|
+
'worklet';
|
|
183
|
+
return keyboardHeight.value > 0
|
|
184
|
+
? keyboardHeight.value + paddingProp
|
|
185
|
+
: insets.bottom + paddingProp;
|
|
186
|
+
});
|
|
181
187
|
|
|
182
|
-
//
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
188
|
+
// Animated style for the positioning wrapper
|
|
189
|
+
const positioningStyle = useAnimatedStyle(() => {
|
|
190
|
+
'worklet';
|
|
191
|
+
return {
|
|
192
|
+
bottom: bottomOffset.value,
|
|
193
|
+
};
|
|
194
|
+
});
|
|
186
195
|
|
|
187
196
|
// Resolve explicit height (number or percentage string)
|
|
188
197
|
const resolvedHeight = typeof height === 'string'
|
|
189
198
|
? height.endsWith('%')
|
|
190
|
-
? (parseFloat(height) / 100) *
|
|
199
|
+
? (parseFloat(height) / 100) * screenHeight // approximate; animated version below handles it
|
|
191
200
|
: parseFloat(height)
|
|
192
201
|
: height;
|
|
193
202
|
|
|
194
|
-
//
|
|
195
|
-
//
|
|
196
|
-
const
|
|
203
|
+
// Only apply flex: 1 to content when the dialog has a definite height to flex against.
|
|
204
|
+
// Without a definite height, flex: 1 collapses content instead of wrapping naturally.
|
|
205
|
+
const hasDefiniteHeight = Boolean(resolvedHeight || maxContentHeight);
|
|
206
|
+
|
|
207
|
+
// Static container styles (not dependent on keyboard)
|
|
208
|
+
const staticContainerStyle = {
|
|
197
209
|
...containerStyle,
|
|
198
|
-
maxHeight: effectiveMaxHeight,
|
|
199
|
-
height: resolvedHeight
|
|
200
|
-
? Math.min(resolvedHeight, effectiveMaxHeight)
|
|
201
|
-
: maxContentHeight
|
|
202
|
-
? effectiveMaxHeight
|
|
203
|
-
: undefined,
|
|
204
210
|
flex: undefined,
|
|
205
211
|
};
|
|
206
212
|
|
|
207
|
-
//
|
|
208
|
-
|
|
209
|
-
|
|
213
|
+
// Animated maxHeight/height that responds to keyboard changes
|
|
214
|
+
const dialogSizeStyle = useAnimatedStyle(() => {
|
|
215
|
+
'worklet';
|
|
216
|
+
const currentBottom = bottomOffset.value;
|
|
217
|
+
const maxAvailable = screenHeight - topOffset - currentBottom;
|
|
218
|
+
const effectiveMax = maxContentHeight
|
|
219
|
+
? Math.min(maxContentHeight, maxAvailable)
|
|
220
|
+
: maxAvailable;
|
|
221
|
+
|
|
222
|
+
const result: { maxHeight: number; height?: number } = {
|
|
223
|
+
maxHeight: effectiveMax,
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
if (resolvedHeight) {
|
|
227
|
+
result.height = Math.min(resolvedHeight, effectiveMax);
|
|
228
|
+
} else if (maxContentHeight) {
|
|
229
|
+
result.height = effectiveMax;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return result;
|
|
233
|
+
});
|
|
210
234
|
|
|
211
235
|
const dialogContainer = (
|
|
212
|
-
<Animated.View
|
|
236
|
+
<Animated.View
|
|
237
|
+
ref={ref as any}
|
|
238
|
+
style={[staticContainerStyle, style, dialogSizeStyle, containerAnimatedStyle]}
|
|
239
|
+
nativeID={id}
|
|
240
|
+
{...nativeA11yProps}
|
|
241
|
+
>
|
|
213
242
|
{(title || showCloseButton) && (
|
|
214
243
|
<View style={[headerStyle, { flexShrink: 0 }]}>
|
|
215
244
|
{title && (
|
|
@@ -259,25 +288,24 @@ const Dialog = forwardRef<View, DialogProps>(({
|
|
|
259
288
|
</TouchableWithoutFeedback>
|
|
260
289
|
)}
|
|
261
290
|
{/* Dialog content - positioned absolute, accounts for keyboard and safe areas */}
|
|
262
|
-
<View
|
|
263
|
-
style={{
|
|
291
|
+
<Animated.View
|
|
292
|
+
style={[{
|
|
264
293
|
position: 'absolute',
|
|
265
294
|
top: topOffset,
|
|
266
295
|
left: 0,
|
|
267
296
|
right: 0,
|
|
268
|
-
bottom: bottomOffset,
|
|
269
297
|
alignItems: 'center',
|
|
270
298
|
justifyContent: 'center',
|
|
271
299
|
zIndex: 1001,
|
|
272
|
-
}}
|
|
300
|
+
}, positioningStyle]}
|
|
273
301
|
pointerEvents="box-none"
|
|
274
302
|
>
|
|
275
303
|
{dialogContainer}
|
|
276
|
-
</View>
|
|
304
|
+
</Animated.View>
|
|
277
305
|
</Modal>
|
|
278
306
|
);
|
|
279
307
|
});
|
|
280
308
|
|
|
281
309
|
Dialog.displayName = 'Dialog';
|
|
282
310
|
|
|
283
|
-
export default Dialog;
|
|
311
|
+
export default Dialog;
|
|
@@ -33,21 +33,25 @@ const noop = () => {};
|
|
|
33
33
|
/**
|
|
34
34
|
* Wraps a React Native GestureResponderEvent into a standardized PressEvent.
|
|
35
35
|
* Pass the component's ref object as `targetRef` so consumers can use it for anchoring.
|
|
36
|
+
* preventDefault() and stopPropagation() are no-ops on native but still update flags.
|
|
36
37
|
*/
|
|
37
38
|
export function createPressEvent(
|
|
38
39
|
event: GestureResponderEvent,
|
|
39
40
|
type: PressEvent['type'] = 'press',
|
|
40
41
|
targetRef?: RefObject<IdealystElement>
|
|
41
42
|
): PressEvent {
|
|
43
|
+
let defaultPrevented = false;
|
|
44
|
+
let propagationStopped = false;
|
|
45
|
+
|
|
42
46
|
return {
|
|
43
47
|
nativeEvent: event.nativeEvent,
|
|
44
48
|
timestamp: event.nativeEvent.timestamp,
|
|
45
|
-
defaultPrevented
|
|
46
|
-
propagationStopped
|
|
49
|
+
get defaultPrevented() { return defaultPrevented; },
|
|
50
|
+
get propagationStopped() { return propagationStopped; },
|
|
47
51
|
type,
|
|
48
52
|
targetRef: targetRef ?? { current: event.target },
|
|
49
|
-
preventDefault
|
|
50
|
-
stopPropagation
|
|
53
|
+
preventDefault() { defaultPrevented = true; },
|
|
54
|
+
stopPropagation() { propagationStopped = true; },
|
|
51
55
|
};
|
|
52
56
|
}
|
|
53
57
|
|
|
@@ -23,21 +23,32 @@ type ReactFormEvent = React.FormEvent<HTMLFormElement>;
|
|
|
23
23
|
type ReactUIEvent = React.UIEvent<HTMLElement>;
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* Wraps a React mouse/click event into a standardized PressEvent
|
|
26
|
+
* Wraps a React mouse/click event into a standardized PressEvent.
|
|
27
|
+
* preventDefault() and stopPropagation() call through to the underlying
|
|
28
|
+
* React event and also update the PressEvent's own flags.
|
|
27
29
|
*/
|
|
28
30
|
export function createPressEvent(
|
|
29
31
|
event: ReactMouseEvent,
|
|
30
32
|
type: PressEvent['type'] = 'press'
|
|
31
33
|
): PressEvent {
|
|
34
|
+
let defaultPrevented = event.defaultPrevented;
|
|
35
|
+
let propagationStopped = false;
|
|
36
|
+
|
|
32
37
|
return {
|
|
33
38
|
nativeEvent: event.nativeEvent,
|
|
34
39
|
timestamp: event.timeStamp,
|
|
35
|
-
defaultPrevented
|
|
36
|
-
propagationStopped
|
|
40
|
+
get defaultPrevented() { return defaultPrevented; },
|
|
41
|
+
get propagationStopped() { return propagationStopped; },
|
|
37
42
|
type,
|
|
38
43
|
targetRef: { current: event.currentTarget },
|
|
39
|
-
preventDefault
|
|
40
|
-
|
|
44
|
+
preventDefault() {
|
|
45
|
+
defaultPrevented = true;
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
},
|
|
48
|
+
stopPropagation() {
|
|
49
|
+
propagationStopped = true;
|
|
50
|
+
event.stopPropagation();
|
|
51
|
+
},
|
|
41
52
|
};
|
|
42
53
|
}
|
|
43
54
|
|