@apple-pie/slice-native 0.1.6 → 0.1.7
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/README.md +138 -261
- package/SliceNative.podspec +24 -0
- package/dist/cjs/components.js +4 -0
- package/dist/cjs/hooks.js +2 -0
- package/dist/cjs/index.js +9 -0
- package/dist/cjs/src/components/SliceBackgroundBlur/SliceBackgroundBlur.js +11 -0
- package/dist/cjs/src/components/SliceButton/SliceButton.js +50 -23
- package/dist/cjs/src/components/SliceLiquidGlassView/SliceLiquidGlassView.js +12 -0
- package/dist/cjs/src/components/SliceTextInput/SliceTextInput.js +39 -9
- package/dist/cjs/src/hooks/useDeviceCapabilities/useDeviceCapabilities.js +19 -0
- package/dist/cjs/src/utils/sizes/sizes.js +40 -0
- package/dist/cjs/utils.js +3 -0
- package/dist/esm/components.mjs +2 -0
- package/dist/esm/hooks.mjs +1 -0
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/src/components/SliceBackgroundBlur/SliceBackgroundBlur.mjs +9 -0
- package/dist/esm/src/components/SliceButton/SliceButton.mjs +50 -23
- package/dist/esm/src/components/SliceLiquidGlassView/SliceLiquidGlassView.mjs +10 -0
- package/dist/esm/src/components/SliceTextInput/SliceTextInput.mjs +39 -9
- package/dist/esm/src/hooks/useDeviceCapabilities/useDeviceCapabilities.mjs +17 -0
- package/dist/esm/src/utils/sizes/sizes.mjs +37 -0
- package/dist/esm/utils.mjs +1 -0
- package/dist/react-native/native/src/components/SliceBackgroundBlur/SliceBackgroundBlur.js +6 -0
- package/dist/react-native/native/src/components/SliceBackgroundBlur/SliceBackgroundBlur.native.js +6 -0
- package/dist/react-native/native/src/components/SliceBackgroundBlur/_types.js +1 -0
- package/dist/react-native/native/src/components/SliceBackgroundBlur/index.js +1 -0
- package/dist/react-native/native/src/components/SliceButton/SliceButton.js +141 -0
- package/dist/react-native/native/src/components/SliceButton/_types.js +1 -0
- package/dist/react-native/native/src/components/SliceButton/index.js +1 -0
- package/dist/react-native/native/src/components/SliceIcon/SliceIcon.js +15 -0
- package/dist/react-native/native/src/components/SliceIcon/_types.js +1 -0
- package/dist/react-native/native/src/components/SliceIcon/iconRegistry.js +663 -0
- package/dist/react-native/native/src/components/SliceIcon/icons.js +140 -0
- package/dist/react-native/native/src/components/SliceIcon/index.js +2 -0
- package/dist/react-native/native/src/components/SliceLiquidGlassView/SliceLiquidGlassView.ios.js +6 -0
- package/dist/react-native/native/src/components/SliceLiquidGlassView/SliceLiquidGlassView.js +7 -0
- package/dist/react-native/native/src/components/SliceLiquidGlassView/_types.js +1 -0
- package/dist/react-native/native/src/components/SliceLiquidGlassView/index.js +1 -0
- package/dist/react-native/native/src/components/SliceText/SliceText.js +16 -0
- package/dist/react-native/native/src/components/SliceText/_types.js +1 -0
- package/dist/react-native/native/src/components/SliceText/index.js +1 -0
- package/dist/react-native/native/src/components/SliceTextInput/SliceTextInput.js +111 -0
- package/dist/react-native/native/src/components/SliceTextInput/_types.js +1 -0
- package/dist/react-native/native/src/components/SliceTextInput/index.js +1 -0
- package/dist/react-native/native/src/components/index.js +6 -0
- package/dist/react-native/native/src/hooks/index.js +2 -0
- package/dist/react-native/native/src/hooks/useCreateThemedStyles/index.js +1 -0
- package/dist/react-native/native/src/hooks/useCreateThemedStyles/useCreateThemedStyles.js +8 -0
- package/dist/react-native/native/src/hooks/useDeviceCapabilities/_types.js +1 -0
- package/dist/react-native/native/src/hooks/useDeviceCapabilities/index.js +1 -0
- package/dist/react-native/native/src/hooks/useDeviceCapabilities/useDeviceCapabilities.js +14 -0
- package/dist/react-native/native/src/hooks/useDeviceCapabilities/useDeviceCapabilities.native.js +23 -0
- package/dist/react-native/native/src/index.js +6 -0
- package/dist/react-native/native/src/providers/SliceThemeProvider.js +30 -0
- package/dist/react-native/native/src/providers/index.js +1 -0
- package/dist/react-native/native/src/specs/BackgroundBlurNativeComponent.ts +16 -0
- package/dist/react-native/native/src/specs/LiquidGlassNativeComponent.ts +18 -0
- package/dist/react-native/native/src/specs/NativeDeviceCapabilities.ts +13 -0
- package/dist/react-native/native/src/theme/index.js +69 -0
- package/dist/react-native/native/src/theme/motion.js +43 -0
- package/dist/react-native/native/src/types/index.js +1 -0
- package/dist/react-native/native/src/types/sharedTypes.js +1 -0
- package/dist/react-native/native/src/utils/index.js +2 -0
- package/dist/react-native/native/src/utils/sizes/index.js +1 -0
- package/dist/react-native/native/src/utils/sizes/sizes.js +35 -0
- package/dist/react-native/native/src/utils/typography/index.js +1 -0
- package/dist/react-native/native/src/utils/typography/typography.js +13 -0
- package/dist/react-native/src/theme/colors/colors.js +385 -0
- package/dist/react-native/src/theme/colors/types.js +1 -0
- package/dist/react-native/src/theme/corners/corners.js +10 -0
- package/dist/react-native/src/theme/corners/types.js +1 -0
- package/dist/react-native/src/theme/elevations/_types.js +1 -0
- package/dist/react-native/src/theme/elevations/elevations.js +13 -0
- package/dist/react-native/src/theme/motion/_types.js +1 -0
- package/dist/react-native/src/theme/motion/motion.js +11 -0
- package/dist/react-native/src/theme/spacing/_types.js +1 -0
- package/dist/react-native/src/theme/spacing/spacing.js +10 -0
- package/dist/react-native/src/theme/type/type.js +371 -0
- package/dist/react-native/src/theme/type/types.js +1 -0
- package/dist/types/native/src/components/SliceBackgroundBlur/SliceBackgroundBlur.d.ts +3 -0
- package/dist/types/native/src/components/SliceBackgroundBlur/SliceBackgroundBlur.native.d.ts +2 -0
- package/dist/types/native/src/components/SliceBackgroundBlur/_types.d.ts +24 -0
- package/dist/types/native/src/components/SliceBackgroundBlur/index.d.ts +2 -0
- package/dist/types/native/src/components/SliceButton/_types.d.ts +33 -2
- package/dist/types/native/src/components/SliceLiquidGlassView/SliceLiquidGlassView.d.ts +3 -0
- package/dist/types/native/src/components/SliceLiquidGlassView/SliceLiquidGlassView.ios.d.ts +2 -0
- package/dist/types/native/src/components/SliceLiquidGlassView/_types.d.ts +17 -0
- package/dist/types/native/src/components/SliceLiquidGlassView/index.d.ts +2 -0
- package/dist/types/native/src/components/SliceTextInput/_types.d.ts +23 -1
- package/dist/types/native/src/components/index.d.ts +4 -0
- package/dist/types/native/src/hooks/index.d.ts +2 -0
- package/dist/types/native/src/hooks/useDeviceCapabilities/_types.d.ts +17 -0
- package/dist/types/native/src/hooks/useDeviceCapabilities/index.d.ts +2 -0
- package/dist/types/native/src/hooks/useDeviceCapabilities/useDeviceCapabilities.d.ts +3 -0
- package/dist/types/native/src/hooks/useDeviceCapabilities/useDeviceCapabilities.native.d.ts +7 -0
- package/dist/types/native/src/index.d.ts +12 -0
- package/dist/types/native/src/specs/BackgroundBlurNativeComponent.d.ts +9 -0
- package/dist/types/native/src/specs/LiquidGlassNativeComponent.d.ts +9 -0
- package/dist/types/native/src/specs/NativeDeviceCapabilities.d.ts +11 -0
- package/dist/types/native/src/types/index.d.ts +1 -0
- package/dist/types/native/src/types/sharedTypes.d.ts +14 -0
- package/dist/types/native/src/utils/index.d.ts +1 -0
- package/dist/types/native/src/utils/sizes/index.d.ts +1 -0
- package/dist/types/native/src/utils/sizes/sizes.d.ts +7 -0
- package/package.json +30 -13
- package/platform/android/build.gradle +22 -0
- package/platform/android/src/main/AndroidManifest.xml +1 -0
- package/platform/android/src/main/java/com/slice/SliceBackgroundBlurManager.java +28 -0
- package/platform/android/src/main/java/com/slice/SliceBackgroundBlurView.java +98 -0
- package/platform/android/src/main/java/com/slice/SliceDeviceCapabilitiesModule.java +25 -0
- package/platform/android/src/main/java/com/slice/SlicePackage.java +25 -0
- package/platform/ios/BackgroundBlurSurface.swift +89 -0
- package/platform/ios/LiquidGlassSurface.swift +82 -0
- package/platform/ios/RCTBackgroundBlurView.h +3 -0
- package/platform/ios/RCTBackgroundBlurView.mm +42 -0
- package/platform/ios/RCTLiquidGlassView.h +8 -0
- package/platform/ios/RCTLiquidGlassView.mm +73 -0
- package/platform/ios/SliceDeviceCapabilities.h +4 -0
- package/platform/ios/SliceDeviceCapabilities.mm +35 -0
- package/react-native.config.js +1 -0
- package/src/specs/BackgroundBlurNativeComponent.ts +16 -0
- package/src/specs/LiquidGlassNativeComponent.ts +18 -0
- package/src/specs/NativeDeviceCapabilities.ts +13 -0
- package/dist/types/native/index.d.ts +0 -8
package/dist/react-native/native/src/components/SliceBackgroundBlur/SliceBackgroundBlur.native.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { StyleSheet } from 'react-native';
|
|
3
|
+
import NativeBackgroundBlur from '../../specs/BackgroundBlurNativeComponent';
|
|
4
|
+
export function SliceBackgroundBlur({ fadeStop = 0, blurIntensity = 12, direction = 'down', fallbackColor = 'rgba(128, 128, 128, 0.18)', style, }) {
|
|
5
|
+
return (_jsx(NativeBackgroundBlur, { pointerEvents: "none", fadeStop: Number.isFinite(fadeStop) ? Math.max(0, Math.min(1, fadeStop)) : 0, blurIntensity: Number.isFinite(blurIntensity) ? Math.max(0, Math.min(100, blurIntensity)) : 12, direction: direction, fallbackColor: fallbackColor, style: [StyleSheet.absoluteFill, style] }));
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SliceBackgroundBlur } from './SliceBackgroundBlur';
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { Pressable, StyleSheet } from 'react-native';
|
|
4
|
+
import Reanimated from 'react-native-reanimated';
|
|
5
|
+
import { useDeviceCapabilities } from '../../hooks';
|
|
6
|
+
import { useSliceTheme } from '../../providers';
|
|
7
|
+
import { borderRadiusToNumber, sizeToNumber } from '../../utils';
|
|
8
|
+
import { SliceIcon } from '../SliceIcon';
|
|
9
|
+
import { SliceLiquidGlassView } from '../SliceLiquidGlassView';
|
|
10
|
+
import { StyledText } from '../SliceText';
|
|
11
|
+
/**
|
|
12
|
+
* Component logic & render
|
|
13
|
+
*/
|
|
14
|
+
export function SliceButton(props) {
|
|
15
|
+
const { colors, name } = useSliceTheme();
|
|
16
|
+
const { supportsLiquidGlass } = useDeviceCapabilities();
|
|
17
|
+
const isLightTheme = name.includes('light');
|
|
18
|
+
const { children, onPress, disabled = false, icon, iconPosition = 'left', iconSize = 24, size = 'm', animatedStyle, variant = 'primary', layout, presence, accessibilityState, liquidGlassBackground, borderRadius = 'pill', borderWidth, borderColor = colors['core-outline-secondary'], backgroundColor, ...pressableProps } = props;
|
|
19
|
+
const { fallbackColor, glassTintColor, glassStyle } = liquidGlassBackground ?? {};
|
|
20
|
+
const applyLiquidGlass = Boolean(liquidGlassBackground) && supportsLiquidGlass;
|
|
21
|
+
const hasLabel = children !== undefined && children !== null && children !== false && children !== '';
|
|
22
|
+
const pressableStyle = useMemo(() => {
|
|
23
|
+
if (!hasLabel)
|
|
24
|
+
return StyleSheet.compose(styles.pressable, styles.pressableNoLabel);
|
|
25
|
+
if (icon && iconPosition === 'left')
|
|
26
|
+
return StyleSheet.compose(styles.pressable, styles.pressableIconLeft);
|
|
27
|
+
if (icon && iconPosition === 'right')
|
|
28
|
+
return StyleSheet.compose(styles.pressable, styles.pressableIconRight);
|
|
29
|
+
return styles.pressable;
|
|
30
|
+
}, [icon, iconPosition, hasLabel]);
|
|
31
|
+
const bgColor = useMemo(() => {
|
|
32
|
+
if (applyLiquidGlass)
|
|
33
|
+
return 'transparent';
|
|
34
|
+
const baseBGColor = variant === 'primary' ? colors['core-button-primary'] : colors['core-surface-primary'];
|
|
35
|
+
return backgroundColor ?? fallbackColor ?? baseBGColor;
|
|
36
|
+
}, [applyLiquidGlass, backgroundColor, fallbackColor, colors, variant]);
|
|
37
|
+
const colorStyles = useMemo(() => {
|
|
38
|
+
const disabledBGColor = disabled ? colors['core-surface-secondary'] : undefined;
|
|
39
|
+
const color = colors['core-text-primary'];
|
|
40
|
+
const disabledColor = disabled ? colors['core-text-disabled'] : undefined;
|
|
41
|
+
const iconColor = disabled
|
|
42
|
+
? disabledColor
|
|
43
|
+
: isLightTheme
|
|
44
|
+
? colors['core-icon-primary']
|
|
45
|
+
: colors['core-link-primary'];
|
|
46
|
+
return StyleSheet.create({
|
|
47
|
+
backgroundColor: {
|
|
48
|
+
backgroundColor: applyLiquidGlass ? 'transparent' : (disabledBGColor ?? bgColor),
|
|
49
|
+
},
|
|
50
|
+
textColor: {
|
|
51
|
+
color: disabledColor ?? color,
|
|
52
|
+
},
|
|
53
|
+
ripple: {
|
|
54
|
+
color: 'rgba(255,255,255,0.5)',
|
|
55
|
+
},
|
|
56
|
+
icon: {
|
|
57
|
+
color: iconColor,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}, [applyLiquidGlass, disabled, colors, isLightTheme, bgColor]);
|
|
61
|
+
// Preserve variant defaults while allowing an explicit zero-width border.
|
|
62
|
+
const borderStyles = useMemo(() => {
|
|
63
|
+
const width = borderWidth ?? (variant === 'primary' ? 0 : 1);
|
|
64
|
+
return StyleSheet.create({
|
|
65
|
+
border: {
|
|
66
|
+
borderWidth: Number.isFinite(width) ? Math.max(0, width) : 0,
|
|
67
|
+
borderColor,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}, [variant, borderColor, borderWidth]);
|
|
71
|
+
// disable touch events when button is disabled
|
|
72
|
+
const pointerEvents = useMemo(() => {
|
|
73
|
+
return StyleSheet.create({
|
|
74
|
+
pointer: {
|
|
75
|
+
pointerEvents: disabled ? 'none' : 'auto',
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
}, [disabled]);
|
|
79
|
+
// set the button size
|
|
80
|
+
const buttonSize = useMemo(() => {
|
|
81
|
+
return StyleSheet.create({
|
|
82
|
+
size: {
|
|
83
|
+
minHeight: sizeToNumber(size),
|
|
84
|
+
width: hasLabel ? 'auto' : sizeToNumber(size),
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}, [size, hasLabel]);
|
|
88
|
+
// set the button border radius
|
|
89
|
+
const cornerRadius = useMemo(() => {
|
|
90
|
+
return StyleSheet.create({
|
|
91
|
+
borderRadius: {
|
|
92
|
+
borderRadius: borderRadiusToNumber(borderRadius),
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
}, [borderRadius]);
|
|
96
|
+
return (_jsx(Reanimated.View, { layout: layout, children: _jsx(Reanimated.View, { entering: presence?.entering, exiting: presence?.exiting, children: _jsxs(Reanimated.View, { style: [
|
|
97
|
+
styles.wrapper,
|
|
98
|
+
pointerEvents.pointer,
|
|
99
|
+
colorStyles.backgroundColor,
|
|
100
|
+
buttonSize.size,
|
|
101
|
+
borderStyles.border,
|
|
102
|
+
cornerRadius.borderRadius,
|
|
103
|
+
animatedStyle,
|
|
104
|
+
], children: [applyLiquidGlass && (_jsx(SliceLiquidGlassView, { cornerRadius: borderRadiusToNumber(borderRadius), fallbackColor: fallbackColor, glassTintColor: glassTintColor, glassStyle: glassStyle, style: styles.background })), _jsxs(Pressable, { ...pressableProps, accessibilityRole: pressableProps.accessibilityRole ?? 'button', accessibilityState: { ...accessibilityState, disabled }, disabled: disabled, style: pressableStyle, onPress: disabled ? undefined : onPress, android_ripple: pressableProps.android_ripple ?? colorStyles.ripple, children: [icon && iconPosition === 'left' && (_jsx(SliceIcon, { name: icon, size: iconSize, strokeColor: colorStyles.icon.color, pointerEvents: "none", accessible: false })), hasLabel && (_jsx(StyledText, { textStyle: 'body-xl-bold', style: colorStyles.textColor, singleLine: true, numberOfLines: 1, ellipsizeMode: 'tail', children: children })), icon && iconPosition === 'right' && (_jsx(SliceIcon, { name: icon, size: iconSize, strokeColor: colorStyles.icon.color, pointerEvents: "none", accessible: false }))] })] }) }) }));
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Base Styles
|
|
108
|
+
*/
|
|
109
|
+
const styles = StyleSheet.create({
|
|
110
|
+
wrapper: {
|
|
111
|
+
position: 'relative',
|
|
112
|
+
overflow: 'hidden',
|
|
113
|
+
justifyContent: 'center',
|
|
114
|
+
alignItems: 'center',
|
|
115
|
+
width: 'auto',
|
|
116
|
+
},
|
|
117
|
+
background: {
|
|
118
|
+
position: 'absolute',
|
|
119
|
+
inset: 0,
|
|
120
|
+
},
|
|
121
|
+
pressable: {
|
|
122
|
+
flex: 1,
|
|
123
|
+
flexDirection: 'row',
|
|
124
|
+
gap: 6,
|
|
125
|
+
paddingHorizontal: 16,
|
|
126
|
+
justifyContent: 'center',
|
|
127
|
+
alignItems: 'center',
|
|
128
|
+
},
|
|
129
|
+
pressableIconLeft: {
|
|
130
|
+
paddingLeft: 16,
|
|
131
|
+
paddingRight: 22,
|
|
132
|
+
},
|
|
133
|
+
pressableIconRight: {
|
|
134
|
+
paddingLeft: 22,
|
|
135
|
+
paddingRight: 16,
|
|
136
|
+
},
|
|
137
|
+
pressableNoLabel: {
|
|
138
|
+
paddingLeft: 0,
|
|
139
|
+
paddingRight: 0,
|
|
140
|
+
},
|
|
141
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SliceButton } from './SliceButton';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { memo } from 'react';
|
|
3
|
+
import { useColorScheme } from 'react-native';
|
|
4
|
+
import Svg from 'react-native-svg';
|
|
5
|
+
import { STATIC_ICON_REGISTRY } from './iconRegistry';
|
|
6
|
+
export const SliceIcon = memo((props) => {
|
|
7
|
+
const dark = useColorScheme() === 'dark';
|
|
8
|
+
const { name = 'home', size = 20, stroke = 1.5, strokeColor = dark ? '#ffffff' : '#000000', fillColor, fill = false, coverUp = dark ? '#000000' : '#ffffff', toggle = false, disabled = false, onPress, onPressIn, onPressOut, onLongPress, accessibilityState, opacity = 1, ...svgProps } = props;
|
|
9
|
+
const variant = STATIC_ICON_REGISTRY.get(name);
|
|
10
|
+
const shape = toggle ? (variant?.lineOn ?? variant?.line) : variant?.line;
|
|
11
|
+
if (!shape)
|
|
12
|
+
return null;
|
|
13
|
+
return (_jsx(Svg, { width: size, height: size, viewBox: "0 0 20 20", fill: "none", accessibilityRole: onPress || onLongPress ? 'button' : 'image', accessibilityLabel: `${name} icon`, ...svgProps, disabled: disabled, opacity: disabled ? Number(opacity) * 0.5 : opacity, accessibilityState: { ...accessibilityState, disabled }, onPress: disabled ? undefined : onPress, onPressIn: disabled ? undefined : onPressIn, onPressOut: disabled ? undefined : onPressOut, onLongPress: disabled ? undefined : onLongPress, children: shape({ stroke, strokeColor, fillColor: fill ? (fillColor ?? (dark ? 0.2 : 0.125)) : 0, coverUp }) }));
|
|
14
|
+
});
|
|
15
|
+
SliceIcon.displayName = 'SliceIcon';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|