zkit-ui 2.0.6 → 2.0.8

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.
@@ -61,7 +61,7 @@ export type ButtonColors = {
61
61
  loading?: string;
62
62
  pressedOverlay?: string;
63
63
  };
64
- type NativePressableProps = Omit<React.ComponentPropsWithoutRef<typeof Pressable>, 'accessibilityRole' | 'accessibilityState' | 'children' | 'disabled' | 'style'>;
64
+ type NativePressableProps = Omit<React.ComponentPropsWithoutRef<typeof Pressable>, 'accessibilityRole' | 'accessibilityState' | 'children' | 'disabled' | 'role' | 'style'>;
65
65
  export type ButtonRef = React.ComponentRef<typeof Pressable>;
66
66
  export interface ButtonProps extends NativePressableProps {
67
67
  variant?: ButtonVariant;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/Button/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAEV,cAAc,EAId,SAAS,EACT,SAAS,EACT,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAEL,SAAS,EAKT,IAAI,EACL,MAAM,cAAc,CAAC;AAetB,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAC5E,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAC;AAC3F,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAC;AACxD,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAC1D,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,KAAK,CAAC;AAClD,MAAM,MAAM,iBAAiB,GACzB,MAAM,GACN,MAAM,GACN,SAAS,GACT,O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AAC,wBAAwB,CAAC,OAAO,SAAS,CAAC,CAAC,oBAAoB,CAAC,CAAC;CAC7F;AAkxDD,eAAO,MAAM,MAAM,qEAA4B,CAAC"}
@@ -189,6 +189,10 @@ function colorToRgba(color, alpha) {
189
189
  const a = Math.max(0, Math.min(1, alpha));
190
190
  return `rgba(${r},${g},${b},${a})`;
191
191
  }
192
+ function resolveBoxShadowColor(color, opacity) {
193
+ var _a;
194
+ return (_a = colorToRgba(color, opacity)) !== null && _a !== void 0 ? _a : color;
195
+ }
192
196
  function resolveColorToken(input, fallback, theme) {
193
197
  var _a;
194
198
  if (input == null)
@@ -305,13 +309,22 @@ function resolveShadowStyle(shadow, scheme, variant) {
305
309
  return undefined;
306
310
  if (typeof shadow === 'object') {
307
311
  const radius = Math.max(0, (_a = shadow.radius) !== null && _a !== void 0 ? _a : (0, zkit_tools_1.wp)(10));
312
+ const color = (_b = shadow.color) !== null && _b !== void 0 ? _b : '#000000';
313
+ const offsetX = (_c = shadow.offsetX) !== null && _c !== void 0 ? _c : 0;
314
+ const offsetY = (_d = shadow.offsetY) !== null && _d !== void 0 ? _d : (0, zkit_tools_1.wp)(3);
315
+ const opacity = (_e = shadow.opacity) !== null && _e !== void 0 ? _e : (scheme === 'dark' ? 0.28 : 0.14);
316
+ if (react_native_1.Platform.OS === 'web') {
317
+ return {
318
+ boxShadow: `${offsetX}px ${offsetY}px ${radius}px ${resolveBoxShadowColor(color, opacity)}`,
319
+ };
320
+ }
308
321
  return {
309
- shadowColor: (_b = shadow.color) !== null && _b !== void 0 ? _b : '#000000',
322
+ shadowColor: color,
310
323
  shadowOffset: {
311
- width: (_c = shadow.offsetX) !== null && _c !== void 0 ? _c : 0,
312
- height: (_d = shadow.offsetY) !== null && _d !== void 0 ? _d : (0, zkit_tools_1.wp)(3),
324
+ width: offsetX,
325
+ height: offsetY,
313
326
  },
314
- shadowOpacity: (_e = shadow.opacity) !== null && _e !== void 0 ? _e : (scheme === 'dark' ? 0.28 : 0.14),
327
+ shadowOpacity: opacity,
315
328
  shadowRadius: radius,
316
329
  elevation: (_f = shadow.elevation) !== null && _f !== void 0 ? _f : Math.max(0, Math.round(radius * 0.55)),
317
330
  };
@@ -320,10 +333,17 @@ function resolveShadowStyle(shadow, scheme, variant) {
320
333
  if (level <= 0)
321
334
  return undefined;
322
335
  const radius = (0, zkit_tools_1.wp)(level * 5 + 3);
336
+ const offsetY = (0, zkit_tools_1.wp)(level + 1);
337
+ const opacity = scheme === 'dark' ? 0.26 : 0.14;
338
+ if (react_native_1.Platform.OS === 'web') {
339
+ return {
340
+ boxShadow: `0px ${offsetY}px ${radius}px ${resolveBoxShadowColor('#000000', opacity)}`,
341
+ };
342
+ }
323
343
  return {
324
344
  shadowColor: '#000000',
325
- shadowOffset: { width: 0, height: (0, zkit_tools_1.wp)(level + 1) },
326
- shadowOpacity: scheme === 'dark' ? 0.26 : 0.14,
345
+ shadowOffset: { width: 0, height: offsetY },
346
+ shadowOpacity: opacity,
327
347
  shadowRadius: radius,
328
348
  elevation: Math.max(0, Math.round(radius * 0.55)),
329
349
  };
@@ -539,6 +559,17 @@ function resolveWebCursorStyle(disabled) {
539
559
  return undefined;
540
560
  return { cursor: disabled ? 'not-allowed' : 'pointer' };
541
561
  }
562
+ const nativeNonePointerEvents = react_native_1.Platform.OS === 'web' ? undefined : 'none';
563
+ const webNonePointerEventsStyle = react_native_1.Platform.OS === 'web' ? { pointerEvents: 'none' } : undefined;
564
+ function resolveRootAccessibilityRole() {
565
+ return react_native_1.Platform.OS === 'web' ? undefined : 'button';
566
+ }
567
+ function resolveRootPressableProps(props) {
568
+ if (react_native_1.Platform.OS !== 'web')
569
+ return props;
570
+ const { accessibilityRole: _accessibilityRole, role: _role, ...rest } = props;
571
+ return rest;
572
+ }
542
573
  function requiresAnimatedPressEffect(effect) {
543
574
  return (effect === 'scale' ||
544
575
  effect === 'scale-opacity' ||
@@ -707,6 +738,8 @@ function ButtonStaticImpl({ variant = 'solid', tone = 'primary', size = 'md', sh
707
738
  return;
708
739
  onPress === null || onPress === void 0 ? void 0 : onPress(event);
709
740
  }, [interactionDisabled, onPress]);
741
+ const rootAccessibilityRole = resolveRootAccessibilityRole();
742
+ const rootPressableProps = resolveRootPressableProps(pressableProps);
710
743
  const pressOpacityEnabled = !interactionDisabled && (pressEffect === 'auto' || pressEffect === 'opacity');
711
744
  const rootStyle = React.useCallback(({ pressed }) => [
712
745
  styles.root,
@@ -726,19 +759,20 @@ function ButtonStaticImpl({ variant = 'solid', tone = 'primary', size = 'md', sh
726
759
  visualDisabled,
727
760
  webCursorStyle,
728
761
  ]);
729
- return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { ...pressableProps, ref: ref, accessibilityLabel: resolvedAccessibilityLabel, accessibilityRole: "button", accessibilityState: {
762
+ return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { ...rootPressableProps, ref: ref, accessibilityLabel: resolvedAccessibilityLabel, accessibilityRole: rootAccessibilityRole, accessibilityState: {
730
763
  ...accessibilityState,
731
764
  busy: Boolean(loading || (accessibilityState === null || accessibilityState === void 0 ? void 0 : accessibilityState.busy)),
732
765
  disabled: Boolean(interactionDisabled || (accessibilityState === null || accessibilityState === void 0 ? void 0 : accessibilityState.disabled)),
733
- }, disabled: interactionDisabled, hitSlop: hitSlop !== null && hitSlop !== void 0 ? hitSlop : defaultHitSlop, onPress: handlePress, style: rootStyle, testID: testID, children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { pointerEvents: "none", style: [
766
+ }, disabled: interactionDisabled, hitSlop: hitSlop !== null && hitSlop !== void 0 ? hitSlop : defaultHitSlop, onPress: handlePress, style: rootStyle, testID: testID, children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { pointerEvents: nativeNonePointerEvents, style: [
734
767
  styles.content,
768
+ webNonePointerEventsStyle,
735
769
  contentSizeStyle,
736
770
  paddingStyle,
737
771
  radiusStyle,
738
772
  borderStyle,
739
773
  { backgroundColor: visualColors.backgroundColor },
740
774
  contentStyle,
741
- ], children: [LinearGradientComponent && gradientCfg ? ((0, jsx_runtime_1.jsx)(LinearGradientComponent, { pointerEvents: "none", colors: gradientCfg.colors, start: gradientCfg.start, end: gradientCfg.end, style: [react_native_1.StyleSheet.absoluteFillObject, radiusStyle] })) : null, iconOnly ? ((icon !== null && icon !== void 0 ? icon : resolvedText)) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [icon && iconPlacement === 'start' ? ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: [iconBaseBoxStyle, iconPlacedBoxStyle], children: icon })) : null, resolvedText, icon && iconPlacement === 'end' ? ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: [iconBaseBoxStyle, iconPlacedBoxStyle], children: icon })) : null] }))] }) }));
775
+ ], children: [LinearGradientComponent && gradientCfg ? ((0, jsx_runtime_1.jsx)(LinearGradientComponent, { pointerEvents: nativeNonePointerEvents, colors: gradientCfg.colors, start: gradientCfg.start, end: gradientCfg.end, style: [react_native_1.StyleSheet.absoluteFillObject, webNonePointerEventsStyle, radiusStyle] })) : null, iconOnly ? ((icon !== null && icon !== void 0 ? icon : resolvedText)) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [icon && iconPlacement === 'start' ? ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: [iconBaseBoxStyle, iconPlacedBoxStyle], children: icon })) : null, resolvedText, icon && iconPlacement === 'end' ? ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: [iconBaseBoxStyle, iconPlacedBoxStyle], children: icon })) : null] }))] }) }));
742
776
  }
743
777
  function ButtonPressAnimatedImpl({ variant = 'solid', tone = 'primary', size = 'md', shape = 'rounded', block = false, disabled = false, loading = false, loadingMode: _loadingMode = 'inline', pressEffect = 'auto', icon, iconPlacement = 'start', iconOnly = false, color, colors, border, layout, gradient, shadow = 'none', children, style, contentStyle, textStyle, accessibilityLabel, accessibilityState, hitSlop, onPress, onPressIn, onPressOut, testID, ...pressableProps }, ref) {
744
778
  const frame = useButtonFrame({
@@ -816,20 +850,24 @@ function ButtonPressAnimatedImpl({ variant = 'solid', tone = 'primary', size = '
816
850
  }
817
851
  onPressOut === null || onPressOut === void 0 ? void 0 : onPressOut(event);
818
852
  }, [interactionDisabled, onPressOut, pressSv, resolvedPressEffect]);
819
- return ((0, jsx_runtime_1.jsx)(AnimatedPressable, { ...pressableProps, ref: ref, accessibilityLabel: resolvedAccessibilityLabel, accessibilityRole: "button", accessibilityState: {
853
+ const rootAccessibilityRole = resolveRootAccessibilityRole();
854
+ const rootPressableProps = resolveRootPressableProps(pressableProps);
855
+ return ((0, jsx_runtime_1.jsx)(AnimatedPressable, { ...rootPressableProps, ref: ref, accessibilityLabel: resolvedAccessibilityLabel, accessibilityRole: rootAccessibilityRole, accessibilityState: {
820
856
  ...accessibilityState,
821
857
  busy: Boolean(loading || (accessibilityState === null || accessibilityState === void 0 ? void 0 : accessibilityState.busy)),
822
858
  disabled: Boolean(interactionDisabled || (accessibilityState === null || accessibilityState === void 0 ? void 0 : accessibilityState.disabled)),
823
- }, disabled: interactionDisabled, hitSlop: hitSlop !== null && hitSlop !== void 0 ? hitSlop : defaultHitSlop, onPress: handlePress, onPressIn: handlePressIn, onPressOut: handlePressOut, style: [styles.root, rootSizeStyle, radiusStyle, shadowStyle, rootAnimatedStyle, webCursorStyle, style], testID: testID, children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { pointerEvents: "none", style: [
859
+ }, disabled: interactionDisabled, hitSlop: hitSlop !== null && hitSlop !== void 0 ? hitSlop : defaultHitSlop, onPress: handlePress, onPressIn: handlePressIn, onPressOut: handlePressOut, style: [styles.root, rootSizeStyle, radiusStyle, shadowStyle, rootAnimatedStyle, webCursorStyle, style], testID: testID, children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { pointerEvents: nativeNonePointerEvents, style: [
824
860
  styles.content,
861
+ webNonePointerEventsStyle,
825
862
  contentSizeStyle,
826
863
  paddingStyle,
827
864
  radiusStyle,
828
865
  borderStyle,
829
866
  { backgroundColor: visualColors.backgroundColor },
830
867
  contentStyle,
831
- ], children: [LinearGradientComponent && gradientCfg ? ((0, jsx_runtime_1.jsx)(LinearGradientComponent, { pointerEvents: "none", colors: gradientCfg.colors, start: gradientCfg.start, end: gradientCfg.end, style: [react_native_1.StyleSheet.absoluteFillObject, radiusStyle] })) : null, pressHighlightEnabled ? ((0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { pointerEvents: "none", style: [
868
+ ], children: [LinearGradientComponent && gradientCfg ? ((0, jsx_runtime_1.jsx)(LinearGradientComponent, { pointerEvents: nativeNonePointerEvents, colors: gradientCfg.colors, start: gradientCfg.start, end: gradientCfg.end, style: [react_native_1.StyleSheet.absoluteFillObject, webNonePointerEventsStyle, radiusStyle] })) : null, pressHighlightEnabled ? ((0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { pointerEvents: nativeNonePointerEvents, style: [
832
869
  react_native_1.StyleSheet.absoluteFillObject,
870
+ webNonePointerEventsStyle,
833
871
  radiusStyle,
834
872
  { backgroundColor: pressOverlay.color },
835
873
  overlayAnimatedStyle,
@@ -997,20 +1035,24 @@ function ButtonAnimatedImpl({ variant = 'solid', tone = 'primary', size = 'md',
997
1035
  }
998
1036
  onPressOut === null || onPressOut === void 0 ? void 0 : onPressOut(event);
999
1037
  }, [interactionDisabled, onPressOut, pressSv, resolvedPressEffect]);
1000
- return ((0, jsx_runtime_1.jsx)(AnimatedPressable, { ...pressableProps, ref: ref, accessibilityLabel: resolvedAccessibilityLabel, accessibilityRole: "button", accessibilityState: {
1038
+ const rootAccessibilityRole = resolveRootAccessibilityRole();
1039
+ const rootPressableProps = resolveRootPressableProps(pressableProps);
1040
+ return ((0, jsx_runtime_1.jsx)(AnimatedPressable, { ...rootPressableProps, ref: ref, accessibilityLabel: resolvedAccessibilityLabel, accessibilityRole: rootAccessibilityRole, accessibilityState: {
1001
1041
  ...accessibilityState,
1002
1042
  busy: Boolean(loading || (accessibilityState === null || accessibilityState === void 0 ? void 0 : accessibilityState.busy)),
1003
1043
  disabled: Boolean(interactionDisabled || (accessibilityState === null || accessibilityState === void 0 ? void 0 : accessibilityState.disabled)),
1004
- }, disabled: interactionDisabled, hitSlop: hitSlop !== null && hitSlop !== void 0 ? hitSlop : defaultHitSlop, onPress: handlePress, onPressIn: handlePressIn, onPressOut: handlePressOut, style: [styles.root, rootSizeStyle, radiusStyle, shadowStyle, rootAnimatedStyle, webCursorStyle, style], testID: testID, children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { pointerEvents: "none", style: [
1044
+ }, disabled: interactionDisabled, hitSlop: hitSlop !== null && hitSlop !== void 0 ? hitSlop : defaultHitSlop, onPress: handlePress, onPressIn: handlePressIn, onPressOut: handlePressOut, style: [styles.root, rootSizeStyle, radiusStyle, shadowStyle, rootAnimatedStyle, webCursorStyle, style], testID: testID, children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { pointerEvents: nativeNonePointerEvents, style: [
1005
1045
  styles.content,
1046
+ webNonePointerEventsStyle,
1006
1047
  contentSizeStyle,
1007
1048
  paddingStyle,
1008
1049
  radiusStyle,
1009
1050
  borderStyle,
1010
1051
  { backgroundColor: visualColors.backgroundColor },
1011
1052
  contentStyle,
1012
- ], children: [LinearGradientComponent && gradientCfg ? ((0, jsx_runtime_1.jsx)(LinearGradientComponent, { pointerEvents: "none", colors: gradientCfg.colors, start: gradientCfg.start, end: gradientCfg.end, style: [react_native_1.StyleSheet.absoluteFillObject, radiusStyle] })) : null, (0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { pointerEvents: "none", style: [
1053
+ ], children: [LinearGradientComponent && gradientCfg ? ((0, jsx_runtime_1.jsx)(LinearGradientComponent, { pointerEvents: nativeNonePointerEvents, colors: gradientCfg.colors, start: gradientCfg.start, end: gradientCfg.end, style: [react_native_1.StyleSheet.absoluteFillObject, webNonePointerEventsStyle, radiusStyle] })) : null, (0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { pointerEvents: nativeNonePointerEvents, style: [
1013
1054
  react_native_1.StyleSheet.absoluteFillObject,
1055
+ webNonePointerEventsStyle,
1014
1056
  radiusStyle,
1015
1057
  { backgroundColor: pressOverlay.color },
1016
1058
  overlayAnimatedStyle,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zkit-ui",
3
- "version": "2.0.6",
3
+ "version": "2.0.8",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -186,5 +186,5 @@ export function Demo() {
186
186
 
187
187
  - `disabled` 会禁用交互并进入禁用视觉;`loading` 只禁用交互,不强制置灰
188
188
  - 显式传入 `hitSlop` 时以调用侧为准;否则小尺寸和 `link` 会自动补足触控热区
189
- - `accessibilityRole` 固定为 `button`
189
+ - Native 端 `accessibilityRole` 固定为 `button`;Web 端根节点不设置 `button` role,避免 RN Web 将 Button 渲染为真实 `<button>` 后产生嵌套按钮问题
190
190
  - `iconOnly` 必须提供可读的 `accessibilityLabel`,除非 children 是可作为标签的文本
@@ -108,7 +108,7 @@ export type ButtonColors = {
108
108
 
109
109
  type NativePressableProps = Omit<
110
110
  React.ComponentPropsWithoutRef<typeof Pressable>,
111
- 'accessibilityRole' | 'accessibilityState' | 'children' | 'disabled' | 'style'
111
+ 'accessibilityRole' | 'accessibilityState' | 'children' | 'disabled' | 'role' | 'style'
112
112
  >;
113
113
 
114
114
  export type ButtonRef = React.ComponentRef<typeof Pressable>;
@@ -352,6 +352,10 @@ function colorToRgba(color: string, alpha: number) {
352
352
  return `rgba(${r},${g},${b},${a})`;
353
353
  }
354
354
 
355
+ function resolveBoxShadowColor(color: string, opacity: number) {
356
+ return colorToRgba(color, opacity) ?? color;
357
+ }
358
+
355
359
  function resolveColorToken(input: string | undefined, fallback: string, theme: Theme) {
356
360
  if (input == null) return fallback;
357
361
 
@@ -484,13 +488,24 @@ function resolveShadowStyle(
484
488
 
485
489
  if (typeof shadow === 'object') {
486
490
  const radius = Math.max(0, shadow.radius ?? wp(10));
491
+ const color = shadow.color ?? '#000000';
492
+ const offsetX = shadow.offsetX ?? 0;
493
+ const offsetY = shadow.offsetY ?? wp(3);
494
+ const opacity = shadow.opacity ?? (scheme === 'dark' ? 0.28 : 0.14);
495
+
496
+ if (Platform.OS === 'web') {
497
+ return {
498
+ boxShadow: `${offsetX}px ${offsetY}px ${radius}px ${resolveBoxShadowColor(color, opacity)}`,
499
+ } as ViewStyle;
500
+ }
501
+
487
502
  return {
488
- shadowColor: shadow.color ?? '#000000',
503
+ shadowColor: color,
489
504
  shadowOffset: {
490
- width: shadow.offsetX ?? 0,
491
- height: shadow.offsetY ?? wp(3),
505
+ width: offsetX,
506
+ height: offsetY,
492
507
  },
493
- shadowOpacity: shadow.opacity ?? (scheme === 'dark' ? 0.28 : 0.14),
508
+ shadowOpacity: opacity,
494
509
  shadowRadius: radius,
495
510
  elevation: shadow.elevation ?? Math.max(0, Math.round(radius * 0.55)),
496
511
  };
@@ -500,10 +515,19 @@ function resolveShadowStyle(
500
515
  if (level <= 0) return undefined;
501
516
 
502
517
  const radius = wp(level * 5 + 3);
518
+ const offsetY = wp(level + 1);
519
+ const opacity = scheme === 'dark' ? 0.26 : 0.14;
520
+
521
+ if (Platform.OS === 'web') {
522
+ return {
523
+ boxShadow: `0px ${offsetY}px ${radius}px ${resolveBoxShadowColor('#000000', opacity)}`,
524
+ } as ViewStyle;
525
+ }
526
+
503
527
  return {
504
528
  shadowColor: '#000000',
505
- shadowOffset: { width: 0, height: wp(level + 1) },
506
- shadowOpacity: scheme === 'dark' ? 0.26 : 0.14,
529
+ shadowOffset: { width: 0, height: offsetY },
530
+ shadowOpacity: opacity,
507
531
  shadowRadius: radius,
508
532
  elevation: Math.max(0, Math.round(radius * 0.55)),
509
533
  };
@@ -839,6 +863,24 @@ function resolveWebCursorStyle(disabled: boolean): ViewStyle | undefined {
839
863
  return { cursor: disabled ? 'not-allowed' : 'pointer' } as ViewStyle;
840
864
  }
841
865
 
866
+ const nativeNonePointerEvents = Platform.OS === 'web' ? undefined : 'none';
867
+ const webNonePointerEventsStyle =
868
+ Platform.OS === 'web' ? ({ pointerEvents: 'none' } as ViewStyle) : undefined;
869
+
870
+ function resolveRootAccessibilityRole() {
871
+ return Platform.OS === 'web' ? undefined : 'button';
872
+ }
873
+
874
+ function resolveRootPressableProps<T extends object>(props: T): T {
875
+ if (Platform.OS !== 'web') return props;
876
+
877
+ const { accessibilityRole: _accessibilityRole, role: _role, ...rest } = props as T & {
878
+ accessibilityRole?: unknown;
879
+ role?: unknown;
880
+ };
881
+ return rest as T;
882
+ }
883
+
842
884
  function requiresAnimatedPressEffect(effect: ButtonPressEffect | undefined) {
843
885
  return (
844
886
  effect === 'scale' ||
@@ -1161,6 +1203,8 @@ function ButtonStaticImpl(
1161
1203
  },
1162
1204
  [interactionDisabled, onPress]
1163
1205
  );
1206
+ const rootAccessibilityRole = resolveRootAccessibilityRole();
1207
+ const rootPressableProps = resolveRootPressableProps(pressableProps);
1164
1208
  const pressOpacityEnabled = !interactionDisabled && (pressEffect === 'auto' || pressEffect === 'opacity');
1165
1209
  const rootStyle = React.useCallback(
1166
1210
  ({ pressed }: PressableStateCallbackType) => [
@@ -1186,10 +1230,10 @@ function ButtonStaticImpl(
1186
1230
 
1187
1231
  return (
1188
1232
  <Pressable
1189
- {...pressableProps}
1233
+ {...rootPressableProps}
1190
1234
  ref={ref}
1191
1235
  accessibilityLabel={resolvedAccessibilityLabel}
1192
- accessibilityRole="button"
1236
+ accessibilityRole={rootAccessibilityRole}
1193
1237
  accessibilityState={{
1194
1238
  ...accessibilityState,
1195
1239
  busy: Boolean(loading || accessibilityState?.busy),
@@ -1202,9 +1246,10 @@ function ButtonStaticImpl(
1202
1246
  testID={testID}
1203
1247
  >
1204
1248
  <View
1205
- pointerEvents="none"
1249
+ pointerEvents={nativeNonePointerEvents}
1206
1250
  style={[
1207
1251
  styles.content,
1252
+ webNonePointerEventsStyle,
1208
1253
  contentSizeStyle,
1209
1254
  paddingStyle,
1210
1255
  radiusStyle,
@@ -1215,11 +1260,11 @@ function ButtonStaticImpl(
1215
1260
  >
1216
1261
  {LinearGradientComponent && gradientCfg ? (
1217
1262
  <LinearGradientComponent
1218
- pointerEvents="none"
1263
+ pointerEvents={nativeNonePointerEvents}
1219
1264
  colors={gradientCfg.colors}
1220
1265
  start={gradientCfg.start}
1221
1266
  end={gradientCfg.end}
1222
- style={[StyleSheet.absoluteFillObject, radiusStyle]}
1267
+ style={[StyleSheet.absoluteFillObject, webNonePointerEventsStyle, radiusStyle]}
1223
1268
  />
1224
1269
  ) : null}
1225
1270
 
@@ -1398,13 +1443,15 @@ function ButtonPressAnimatedImpl(
1398
1443
  },
1399
1444
  [interactionDisabled, onPressOut, pressSv, resolvedPressEffect]
1400
1445
  );
1446
+ const rootAccessibilityRole = resolveRootAccessibilityRole();
1447
+ const rootPressableProps = resolveRootPressableProps(pressableProps);
1401
1448
 
1402
1449
  return (
1403
1450
  <AnimatedPressable
1404
- {...pressableProps}
1451
+ {...rootPressableProps}
1405
1452
  ref={ref}
1406
1453
  accessibilityLabel={resolvedAccessibilityLabel}
1407
- accessibilityRole="button"
1454
+ accessibilityRole={rootAccessibilityRole}
1408
1455
  accessibilityState={{
1409
1456
  ...accessibilityState,
1410
1457
  busy: Boolean(loading || accessibilityState?.busy),
@@ -1419,9 +1466,10 @@ function ButtonPressAnimatedImpl(
1419
1466
  testID={testID}
1420
1467
  >
1421
1468
  <View
1422
- pointerEvents="none"
1469
+ pointerEvents={nativeNonePointerEvents}
1423
1470
  style={[
1424
1471
  styles.content,
1472
+ webNonePointerEventsStyle,
1425
1473
  contentSizeStyle,
1426
1474
  paddingStyle,
1427
1475
  radiusStyle,
@@ -1432,19 +1480,20 @@ function ButtonPressAnimatedImpl(
1432
1480
  >
1433
1481
  {LinearGradientComponent && gradientCfg ? (
1434
1482
  <LinearGradientComponent
1435
- pointerEvents="none"
1483
+ pointerEvents={nativeNonePointerEvents}
1436
1484
  colors={gradientCfg.colors}
1437
1485
  start={gradientCfg.start}
1438
1486
  end={gradientCfg.end}
1439
- style={[StyleSheet.absoluteFillObject, radiusStyle]}
1487
+ style={[StyleSheet.absoluteFillObject, webNonePointerEventsStyle, radiusStyle]}
1440
1488
  />
1441
1489
  ) : null}
1442
1490
 
1443
1491
  {pressHighlightEnabled ? (
1444
1492
  <Animated.View
1445
- pointerEvents="none"
1493
+ pointerEvents={nativeNonePointerEvents}
1446
1494
  style={[
1447
1495
  StyleSheet.absoluteFillObject,
1496
+ webNonePointerEventsStyle,
1448
1497
  radiusStyle,
1449
1498
  { backgroundColor: pressOverlay.color },
1450
1499
  overlayAnimatedStyle,
@@ -1736,13 +1785,15 @@ function ButtonAnimatedImpl(
1736
1785
  },
1737
1786
  [interactionDisabled, onPressOut, pressSv, resolvedPressEffect]
1738
1787
  );
1788
+ const rootAccessibilityRole = resolveRootAccessibilityRole();
1789
+ const rootPressableProps = resolveRootPressableProps(pressableProps);
1739
1790
 
1740
1791
  return (
1741
1792
  <AnimatedPressable
1742
- {...pressableProps}
1793
+ {...rootPressableProps}
1743
1794
  ref={ref}
1744
1795
  accessibilityLabel={resolvedAccessibilityLabel}
1745
- accessibilityRole="button"
1796
+ accessibilityRole={rootAccessibilityRole}
1746
1797
  accessibilityState={{
1747
1798
  ...accessibilityState,
1748
1799
  busy: Boolean(loading || accessibilityState?.busy),
@@ -1757,9 +1808,10 @@ function ButtonAnimatedImpl(
1757
1808
  testID={testID}
1758
1809
  >
1759
1810
  <View
1760
- pointerEvents="none"
1811
+ pointerEvents={nativeNonePointerEvents}
1761
1812
  style={[
1762
1813
  styles.content,
1814
+ webNonePointerEventsStyle,
1763
1815
  contentSizeStyle,
1764
1816
  paddingStyle,
1765
1817
  radiusStyle,
@@ -1770,18 +1822,19 @@ function ButtonAnimatedImpl(
1770
1822
  >
1771
1823
  {LinearGradientComponent && gradientCfg ? (
1772
1824
  <LinearGradientComponent
1773
- pointerEvents="none"
1825
+ pointerEvents={nativeNonePointerEvents}
1774
1826
  colors={gradientCfg.colors}
1775
1827
  start={gradientCfg.start}
1776
1828
  end={gradientCfg.end}
1777
- style={[StyleSheet.absoluteFillObject, radiusStyle]}
1829
+ style={[StyleSheet.absoluteFillObject, webNonePointerEventsStyle, radiusStyle]}
1778
1830
  />
1779
1831
  ) : null}
1780
1832
 
1781
1833
  <Animated.View
1782
- pointerEvents="none"
1834
+ pointerEvents={nativeNonePointerEvents}
1783
1835
  style={[
1784
1836
  StyleSheet.absoluteFillObject,
1837
+ webNonePointerEventsStyle,
1785
1838
  radiusStyle,
1786
1839
  { backgroundColor: pressOverlay.color },
1787
1840
  overlayAnimatedStyle,