@webority/mobile-ui 0.130.3 → 0.132.0
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 +6 -0
- package/dist/canvas-kit/kit.js +5054 -4863
- package/dist/canvas-kit/manifest.json +39 -2
- package/dist/canvas-kit/release.json +6 -6
- package/lib/commonjs/components/AppBar/AppBar.js +1 -1
- package/lib/commonjs/components/BarChart/BarChart.js +1 -1
- package/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
- package/lib/commonjs/components/ChoiceGroup/ChoiceGroup.js +1 -1
- package/lib/commonjs/components/Confetti/Confetti.js +1 -1
- package/lib/commonjs/components/Drawer/Drawer.js +1 -1
- package/lib/commonjs/components/FileViewer/FileViewer.js +1 -1
- package/lib/commonjs/components/FileViewer/useFileViewerZoom.js +1 -1
- package/lib/commonjs/components/FloatingActionButton/FloatingActionButton.js +1 -1
- package/lib/commonjs/components/ImageGallery/ImageGallery.js +1 -1
- package/lib/commonjs/components/MessageList/MessageList.js +1 -1
- package/lib/commonjs/components/OTPInput/OTPInput.js +1 -1
- package/lib/commonjs/components/ScannerOverlay/ScannerOverlay.js +1 -1
- package/lib/commonjs/components/Screen/Screen.js +1 -1
- package/lib/commonjs/components/SegmentedControl/SegmentedControl.js +1 -1
- package/lib/commonjs/components/SlideToConfirm/SlideToConfirm.js +1 -1
- package/lib/commonjs/components/Slider/Slider.js +1 -1
- package/lib/commonjs/components/SortableList/SortableList.js +1 -1
- package/lib/commonjs/components/Swipeable/Swipeable.js +1 -1
- package/lib/commonjs/components/TypingIndicator/TypingIndicator.js +1 -1
- package/lib/commonjs/components/WheelPicker/Wheel.js +1 -1
- package/lib/commonjs/components/ZoomableImage/ZoomableImage.js +1 -1
- package/lib/commonjs/navigation/NavigationScreen.js +1 -1
- package/lib/commonjs/network/NetworkStatusBanner.js +1 -1
- package/lib/commonjs/theme/merge.js +1 -1
- package/lib/commonjs/theme/tokens.generated.js +1 -1
- package/lib/module/components/AppBar/AppBar.js +1 -1
- package/lib/module/components/BarChart/BarChart.js +1 -1
- package/lib/module/components/BottomSheet/BottomSheet.js +1 -1
- package/lib/module/components/ChoiceGroup/ChoiceGroup.js +1 -1
- package/lib/module/components/Confetti/Confetti.js +1 -1
- package/lib/module/components/Drawer/Drawer.js +1 -1
- package/lib/module/components/FileViewer/FileViewer.js +1 -1
- package/lib/module/components/FileViewer/useFileViewerZoom.js +1 -1
- package/lib/module/components/FloatingActionButton/FloatingActionButton.js +1 -1
- package/lib/module/components/ImageGallery/ImageGallery.js +1 -1
- package/lib/module/components/MessageList/MessageList.js +1 -1
- package/lib/module/components/OTPInput/OTPInput.js +1 -1
- package/lib/module/components/ScannerOverlay/ScannerOverlay.js +1 -1
- package/lib/module/components/Screen/Screen.js +1 -1
- package/lib/module/components/SegmentedControl/SegmentedControl.js +1 -1
- package/lib/module/components/SlideToConfirm/SlideToConfirm.js +1 -1
- package/lib/module/components/Slider/Slider.js +1 -1
- package/lib/module/components/SortableList/SortableList.js +1 -1
- package/lib/module/components/Swipeable/Swipeable.js +1 -1
- package/lib/module/components/TypingIndicator/TypingIndicator.js +1 -1
- package/lib/module/components/WheelPicker/Wheel.js +1 -1
- package/lib/module/components/ZoomableImage/ZoomableImage.js +1 -1
- package/lib/module/navigation/NavigationScreen.js +1 -1
- package/lib/module/network/NetworkStatusBanner.js +1 -1
- package/lib/module/theme/merge.js +1 -1
- package/lib/module/theme/tokens.generated.js +1 -1
- package/lib/typescript/commonjs/components/AppBar/AppBar.d.ts +3 -1
- package/lib/typescript/commonjs/components/ChoiceGroup/ChoiceGroup.d.ts +3 -3
- package/lib/typescript/commonjs/components/MessageList/MessageList.d.ts +1 -1
- package/lib/typescript/commonjs/components/Screen/Screen.d.ts +4 -0
- package/lib/typescript/commonjs/components/SegmentedControl/SegmentedControl.d.ts +2 -1
- package/lib/typescript/commonjs/navigation/NavigationScreen.d.ts +2 -2
- package/lib/typescript/commonjs/network/NetworkStatusBanner.d.ts +7 -2
- package/lib/typescript/commonjs/theme/tokens.generated.d.ts +1 -1
- package/lib/typescript/commonjs/theme/types.d.ts +5 -1
- package/lib/typescript/module/components/AppBar/AppBar.d.ts +3 -1
- package/lib/typescript/module/components/ChoiceGroup/ChoiceGroup.d.ts +3 -3
- package/lib/typescript/module/components/MessageList/MessageList.d.ts +1 -1
- package/lib/typescript/module/components/Screen/Screen.d.ts +4 -0
- package/lib/typescript/module/components/SegmentedControl/SegmentedControl.d.ts +2 -1
- package/lib/typescript/module/navigation/NavigationScreen.d.ts +2 -2
- package/lib/typescript/module/network/NetworkStatusBanner.d.ts +7 -2
- package/lib/typescript/module/theme/tokens.generated.d.ts +1 -1
- package/lib/typescript/module/theme/types.d.ts +5 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{Logger}from"@webority/mobile-core";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{PixelRatio,ScrollView,StyleSheet,useWindowDimensions,View}from"react-native";import{GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import Animated from"react-native-reanimated";import PdfRasterizer from"../../specs/NativePdfRasterizer.js";import{useTheme}from"../../theme/index.js";import{Spinner}from"../Spinner/index.js";import{FileViewerImage}from"./FileViewerImage.js";import{FileViewerPage}from"./FileViewerPage.js";import{localPathFromSource,resolveKind}from"./fileSource.js";import{useFileViewerZoom,ZOOM_REST}from"./useFileViewerZoom.js";import{jsx as _jsx}from"react/jsx-runtime";const MAX_RENDER_SCALE=5,RENDER_OVERSCALE=1.25,RENDER_AHEAD=3,MOUNT_AROUND=2,DEFAULT_MAX_ZOOM=4,toError=e=>e instanceof Error?e:new Error(String(e)),scaleForWidth=(e,t,r)=>{if(t<=0)return 1;const i=e/t*PixelRatio.get()*1.25*r;return Math.round(100*Math.min(Math.max(i,1),5))/100},AnimatedScrollView=Animated.createAnimatedComponent(ScrollView),FileViewerPdf=({source:e,onLoadComplete:t,onPageChanged:r,onError:i,loadingIndicator:o,zoomEnabled:s=!0,maxZoom:
|
|
1
|
+
"use strict";import{Logger}from"@webority/mobile-core";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{PixelRatio,ScrollView,StyleSheet,useWindowDimensions,View}from"react-native";import{GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import Animated from"react-native-reanimated";import PdfRasterizer from"../../specs/NativePdfRasterizer.js";import{useTheme}from"../../theme/index.js";import{Spinner}from"../Spinner/index.js";import{FileViewerImage}from"./FileViewerImage.js";import{FileViewerPage}from"./FileViewerPage.js";import{localPathFromSource,resolveKind}from"./fileSource.js";import{useFileViewerZoom,ZOOM_REST}from"./useFileViewerZoom.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const MAX_RENDER_SCALE=5,RENDER_OVERSCALE=1.25,RENDER_AHEAD=3,MOUNT_AROUND=2,DEFAULT_MAX_ZOOM=4,toError=e=>e instanceof Error?e:new Error(String(e)),scaleForWidth=(e,t,r)=>{if(t<=0)return 1;const i=e/t*PixelRatio.get()*1.25*r;return Math.round(100*Math.min(Math.max(i,1),5))/100},AnimatedScrollView=Animated.createAnimatedComponent(ScrollView),FileViewerPdf=({source:e,onLoadComplete:t,onPageChanged:r,onError:i,loadingIndicator:o,zoomEnabled:s=!0,maxZoom:n=4,style:a,testID:l,accessibilityLabel:c})=>{const u=useTheme().space.sm,{width:d,height:h}=useWindowDimensions(),[m,f]=useState({width:0,height:0}),w=m.width>0?m.width:d,[g,p]=useState(0),[R,S]=useState({width:612,height:792}),y=R.height/R.width,[E,x]=useState({}),[b,V]=useState(null),[j,_]=useState(0),v=useRef(0),F=useRef(null),P=useRef(null),M=useRef(i);M.current=i;const z=useRef(t);z.current=t;const A=useRef(r);A.current=r;const C=useRef(o);C.current=o;const O=w*y,D=O+u,L=m.height>0?m.height:h,{scrollRef:Z,scrollGesture:T,zoomGesture:k,zoomStyle:I,zoomLevel:W,resetZoom:G}=useFileViewerZoom({zoomEnabled:s,maxZoom:n,viewportWidth:m.width>0?m.width:d,viewportHeight:L,maxScroll:Math.max(0,g*D-u-L)}),N=useMemo(()=>({uri:e.uri,headers:e.headers,client:e.client,cache:e.cache}),[e.uri,e.headers,e.client,e.cache]);useEffect(()=>{let e=!1;return(async()=>{if(PdfRasterizer)try{const t=await localPathFromSource(N);if(e)return;const r=await PdfRasterizer.open(t);if(e)return void await PdfRasterizer.close(r.handle).catch(()=>{});F.current=r.handle,v.current=0,p(r.pageCount),_(0),x({}),V(null),G(),r.pageWidth>0&&r.pageHeight>0&&S({width:r.pageWidth,height:r.pageHeight}),z.current?.(r.pageCount)}catch(t){if(!e){const e=toError(t);Logger.error("[@webority/mobile-ui] FileViewer failed to load.",e),M.current?.(e)}}else M.current?.(new Error("[@webority/mobile-ui] PdfRasterizer native module is not linked. Run pod install / rebuild the app after adding @webority/mobile-ui."))})(),()=>{e=!0;const t=F.current;F.current=null,t&&PdfRasterizer?.close(t).catch(()=>{})}},[N,G]);const H=scaleForWidth(w,R.width,1),U=W>ZOOM_REST?scaleForWidth(w,R.width,Math.ceil(W)):0,K=useRef(H);K.current=H;const X=useRef(U);X.current=U;const $=useRef(H);useEffect(()=>{$.current!==H&&($.current=H,x({}))},[H]);const q=useCallback(async()=>{const e=F.current;if(!e||!PdfRasterizer||0===g)return;if(P.current===e)return;let t;if(void 0===E[j])t={page:j,scale:H,sharp:!1};else if(U>H&&null!==E[j]&&(b?.page!==j||b.scale!==U))t={page:j,scale:U,sharp:!0};else for(let e=1;e<=3&&!t;e+=1)for(const r of[j+e,j-e])if(r>=0&&r<g&&void 0===E[r]){t={page:r,scale:H,sharp:!1};break}if(!t)return;const{page:r,scale:i,sharp:o}=t;P.current=e;let s=null;try{s=await PdfRasterizer.renderPage(e,r,i)}catch(t){F.current===e&&Logger.error(`[@webority/mobile-ui] FileViewer failed to render page ${r}.`,toError(t))}finally{P.current===e&&(P.current=null)}F.current===e&&(i===(o?X.current:K.current)?o?V({page:r,scale:i,uri:s}):x(e=>({...e,[r]:s})):x(e=>({...e})))},[H,j,g,E,b,U]);useEffect(()=>{q()},[q]),useEffect(()=>{W<=ZOOM_REST&&V(null)},[W]);const B=useCallback(e=>{const{width:t,height:r}=e.nativeEvent.layout;f(e=>e.width===t&&e.height===r?e:{width:t,height:r})},[]),J=useCallback(e=>{if(D<=0||0===g)return;const t=Math.min(g-1,Math.max(0,Math.round(e.nativeEvent.contentOffset.y/D)));t!==v.current&&(v.current=t,_(t),A.current?.(t+1,g))},[g,D]),Q=useCallback(()=>C.current?.()??_jsx(Spinner,{size:"lg"}),[]),Y=useMemo(()=>({gap:u}),[u]),ee=useMemo(()=>Array.from({length:g},(e,t)=>t),[g]),te=W>ZOOM_REST;return _jsxs(GestureHandlerRootView,{style:[styles.root,a],onLayout:B,testID:l,accessible:void 0!==c,accessibilityLabel:c,accessibilityRole:"none",children:[_jsx(GestureDetector,{gesture:k,children:_jsx(View,{style:styles.viewport,collapsable:!1,children:_jsx(Animated.View,{style:[styles.viewport,I],children:_jsx(GestureDetector,{gesture:T,children:_jsx(AnimatedScrollView,{ref:Z,onScroll:J,scrollEventThrottle:16,scrollEnabled:!te,showsVerticalScrollIndicator:!te,contentContainerStyle:Y,children:ee.map(e=>_jsx(FileViewerPage,{width:w,height:O,uri:te&&b?.page===e&&b.uri?b.uri:E[e],mounted:Math.abs(e-j)<=2,renderLoading:Q},e))})})})})}),0===g&&_jsx(View,{pointerEvents:"none",style:[StyleSheet.absoluteFill,styles.pagePlaceholder],children:o?o():_jsx(Spinner,{size:"lg"})})]})};export const FileViewer=({kind:e="auto",...t})=>"image"===resolveKind(e,t.source.uri)?_jsx(FileViewerImage,{...t}):_jsx(FileViewerPdf,{...t});FileViewer.displayName="FileViewer";const styles=StyleSheet.create({root:{flex:1,overflow:"hidden"},viewport:{flex:1},pagePlaceholder:{flex:1,alignItems:"center",justifyContent:"center"}});export default FileViewer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useCallback,useEffect,useMemo,useState}from"react";import{Gesture}from"react-native-gesture-handler";import{runOnJS,scrollTo,useAnimatedRef,useAnimatedStyle,useScrollViewOffset,useSharedValue,withTiming}from"react-native-reanimated";const DOUBLE_TAP_ZOOM=2.5;export const ZOOM_REST=1.01;const clamp=(e,a,l)=>{"worklet";return Math.min(Math.max(e,a),l)},panLimit=(e,a)=>{"worklet";return e*(a-1)/2};export const useFileViewerZoom=({zoomEnabled:e,maxZoom:a,viewportWidth:l,viewportHeight:u,maxScroll:t})=>{const[i,n]=useState(1),v=useAnimatedRef(),r=useScrollViewOffset(v),o=useSharedValue(0),s=useSharedValue(0),m=useSharedValue(0),c=useSharedValue(0),h=useSharedValue(1),d=useSharedValue(1),w=useSharedValue(0),S=useSharedValue(0),p=useSharedValue(0),f=useSharedValue(0);useEffect(()=>{m.value=l,c.value=u,s.value=t},[l,u,t,m,c,s]);const T=useCallback(()=>{h.value=withTiming(1),w.value=withTiming(0),S.value=withTiming(0),d.value=1,p.value=0,f.value=0,n(1)},[h,d,w,S,p,f]);useEffect(()=>{e||T()},[e,T]);const g=useCallback(e=>n(e),[]),V=useMemo(()=>Gesture.Native(),[]),k=useMemo(()=>{const l=Math.max(1,a),u=Math.min(2.5,l),t=Gesture.Pinch().enabled(e).onStart(()=>{"worklet";d.value=h.value,p.value=w.value,f.value=S.value}).onUpdate(e=>{"worklet";const a=clamp(d.value*e.scale,1,l),u=e.focalX-m.value/2,t=e.focalY-c.value/2,i=a/d.value,n=panLimit(m.value,a),v=panLimit(c.value,a);w.value=clamp(u-(u-p.value)*i,-n,n),S.value=clamp(t-(t-f.value)*i,-v,v),h.value=a}).onEnd(()=>{"worklet";if(h.value<=1.01)return h.value=withTiming(1),w.value=withTiming(0),S.value=withTiming(0),d.value=1,p.value=0,f.value=0,void runOnJS(g)(1);d.value=h.value,p.value=w.value,f.value=S.value,runOnJS(g)(h.value)}),i=Gesture.Pan().enabled(e).minPointers(1).maxPointers(1).manualActivation(!0).onTouchesMove((e,a)=>{"worklet";h.value>1.01?a.activate():a.fail()}).onStart(()=>{"worklet";p.value=w.value,f.value=S.value,o.value=r.value}).onUpdate(e=>{"worklet";const a=h.value,l=panLimit(m.value,a),u=panLimit(c.value,a);w.value=clamp(p.value+e.translationX,-l,l);const t=f.value+e.translationY,i=clamp(t,-u,u),n=t-i;if(0!==n){const e=clamp(o.value-n/a,0,s.value);e!==o.value&&(o.value=e,scrollTo(v,0,e,!1)),f.value-=n}S.value=i}).onEnd(()=>{"worklet";p.value=w.value,f.value=S.value}),n=Gesture.Tap().enabled(e).numberOfTaps(2).maxDistance(10).onEnd(e=>{"worklet";if(h.value>1.01)return h.value=withTiming(1),w.value=withTiming(0),S.value=withTiming(0),d.value=1,p.value=0,f.value=0,void runOnJS(g)(1);if(u<=1.01)return;const a=e.x-m.value/2,l=e.y-c.value/2,t=panLimit(m.value,u),i=panLimit(c.value,u),n=clamp(-a*(u-1),-t,t),v=clamp(-l*(u-1),-i,i);h.value=withTiming(u),w.value=withTiming(n),S.value=withTiming(v),d.value=u,p.value=n,f.value=v,runOnJS(g)(u)});return t.simultaneousWithExternalGesture(V),i.simultaneousWithExternalGesture(V),n.simultaneousWithExternalGesture(V),Gesture.Simultaneous(t,i,n)},[a,e,g,V,v,r,o,s,m,c,h,d,w,S,p,f]),O=useAnimatedStyle(()=>({transform:[{translateX:w.value},{translateY:S.value},{scale:h.value}]}));return{scrollRef:v,scrollGesture:V,zoomGesture:k,zoomStyle:O,zoomLevel:i,resetZoom:T}};
|
|
1
|
+
"use strict";import{useCallback,useEffect,useMemo,useState}from"react";import{Gesture}from"react-native-gesture-handler";import{runOnJS,scrollTo,useAnimatedRef,useAnimatedStyle,useScrollViewOffset,useSharedValue,withTiming}from"react-native-reanimated";const DOUBLE_TAP_ZOOM=2.5;export const ZOOM_REST=1.01;const clamp=(e,a,l)=>{"worklet";return Math.min(Math.max(e,a),l)},panLimit=(e,a)=>{"worklet";return e*(a-1)/2};export const useFileViewerZoom=({zoomEnabled:e,maxZoom:a,viewportWidth:l,viewportHeight:u,maxScroll:t})=>{const[i,n]=useState(1),v=useAnimatedRef(),r=useScrollViewOffset(v),o=useSharedValue(0),s=useSharedValue(0),m=useSharedValue(0),c=useSharedValue(0),h=useSharedValue(1),d=useSharedValue(1),w=useSharedValue(0),S=useSharedValue(0),p=useSharedValue(0),f=useSharedValue(0);useEffect(()=>{m.value=l,c.value=u,s.value=t},[l,u,t,m,c,s]);const T=useCallback(()=>{h.value=withTiming(1),w.value=withTiming(0),S.value=withTiming(0),d.value=1,p.value=0,f.value=0,n(1)},[h,d,w,S,p,f]);useEffect(()=>{e||T()},[e,T]);const g=useCallback(e=>n(e),[]),V=useMemo(()=>Gesture.Native(),[]),k=useMemo(()=>{const l=Math.max(1,a),u=Math.min(2.5,l),t=Gesture.Pinch().enabled(e).onStart(()=>{"worklet";d.value=h.value,p.value=w.value,f.value=S.value}).onUpdate(e=>{"worklet";const a=clamp(d.value*e.scale,1,l),u=e.focalX-m.value/2,t=e.focalY-c.value/2,i=a/d.value,n=panLimit(m.value,a),v=panLimit(c.value,a);w.value=clamp(u-(u-p.value)*i,-n,n),S.value=clamp(t-(t-f.value)*i,-v,v),h.value=a}).onEnd(()=>{"worklet";if(h.value<=1.01)return h.value=withTiming(1),w.value=withTiming(0),S.value=withTiming(0),d.value=1,p.value=0,f.value=0,void runOnJS(g)(1);d.value=h.value,p.value=w.value,f.value=S.value,runOnJS(g)(h.value)}),i=Gesture.Pan().enabled(e).minPointers(1).maxPointers(1).manualActivation(!0).onTouchesMove((e,a)=>{"worklet";h.value>1.01?a.activate():a.fail()}).onStart(()=>{"worklet";p.value=w.value,f.value=S.value,o.value=r.value}).onUpdate(e=>{"worklet";const a=h.value,l=panLimit(m.value,a),u=panLimit(c.value,a);w.value=clamp(p.value+e.translationX,-l,l);const t=f.value+e.translationY,i=clamp(t,-u,u),n=t-i;if(0!==n){const e=clamp(o.value-n/a,0,s.value);e!==o.value&&(o.value=e,scrollTo(v,0,e,!1)),f.value-=n}S.value=i}).onEnd(()=>{"worklet";p.value=w.value,f.value=S.value}),n=Gesture.Tap().enabled(e).numberOfTaps(2).maxDistance(10).onEnd(e=>{"worklet";if(h.value>1.01)return h.value=withTiming(1),w.value=withTiming(0),S.value=withTiming(0),d.value=1,p.value=0,f.value=0,void runOnJS(g)(1);if(u<=1.01)return;const a=e.x-m.value/2,l=e.y-c.value/2,t=panLimit(m.value,u),i=panLimit(c.value,u),n=clamp(-a*(u-1),-t,t),v=clamp(-l*(u-1),-i,i);h.value=withTiming(u),w.value=withTiming(n),S.value=withTiming(v),d.value=u,p.value=n,f.value=v,runOnJS(g)(u)});return t.simultaneousWithExternalGesture(V),i.simultaneousWithExternalGesture(V),n.simultaneousWithExternalGesture(V),Gesture.Simultaneous(t,i,n)},[a,e,g,V,v,r,o,s,m,c,h,d,w,S,p,f]),O=useAnimatedStyle(()=>({transform:[{translateX:w.value},{translateY:S.value},{scale:h.value}]}),[w,S,h]);return{scrollRef:v,scrollGesture:V,zoomGesture:k,zoomStyle:O,zoomLevel:i,resetZoom:T}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{Logger}from"@webority/mobile-core";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,BackHandler,Easing,Platform,Pressable,StyleSheet,Text,View}from"react-native";import Reanimated,{cancelAnimation,Easing as ReanimatedEasing,useAnimatedStyle,useSharedValue,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{createAnimatedValue,resolveFloatingActionButtonSize,setNativeValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{ACCENT_PRESSED_TINT}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const FAB_SIZES=["sm","md","lg"],FAB_TONES=["primary","success","warning","danger","info","neutral"],FAB_POSITIONS=["bottomRight","bottomLeft","bottomCenter"],toneBackground=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors["bg-muted"];default:return e.colors.primary}},pressedTintFor=(e,t)=>"neutral"===t?e.colors["surface-pressed"]:ACCENT_PRESSED_TINT,toneForeground=(e,t)=>{if("neutral"===t)return e.colors["text-body"];switch(t){case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];default:return e.colors["on-primary"]}},FloatingActionButton=forwardRef((e,t)=>{const{icon:o,onPress:n,label:i,collapsed:s=!1,size:r="md",tone:a="primary",position:l,bottomOffset:c,disabled:u=!1,loading:d=!1,hideOnScroll:m=!1,isScrolling:p=!1,accessibilityLabel:b,accessibilityHint:g,haptic:f,style:h,containerStyle:y,labelStyle:A,testID:S}=e;warnInvalidValue("FloatingActionButton","size",e.size,FAB_SIZES),warnInvalidValue("FloatingActionButton","tone",e.tone,FAB_TONES),warnInvalidValue("FloatingActionButton","position",e.position,FAB_POSITIONS);const w=!u&&!d,x=useTheme(),_=useSafeAreaInsets(),v=useMemo(()=>resolveFloatingActionButtonSize(x,r),[x,r]),I=useMemo(()=>buildStyles(x),[x]),{scale:E,opacity:R,pressIn:F,pressOut:C}=usePressAnimation({enabled:w}),j=usePresenceMotion(),T=x.space[x.components["floating-action-button"]["edge-offset"]],B=x.space[x.components["floating-action-button"]["bottom-offset"]],P=useRef(createAnimatedValue(1)).current,V=j.duration("default");useEffect(()=>{if(!m)return void setNativeValue(P,1);const e=Animated.timing(P,{toValue:p?0:1,duration:V,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:!0});return e.start(),()=>e.stop()},[m,p,P,V,x.motion.ease["in-out"]]);const k=v.diameter+(c??B)+_.bottom+T,O=P.interpolate({inputRange:[0,1],outputRange:j.range(k,0)}),L=useMemo(()=>Animated.multiply(P,R),[P,R]),N="string"==typeof i&&i.length>0,D=N&&s,z=j.reduced,M=x.space.sm,G=v["label-padding-x"],H=x.motion.duration.fast,$=x.motion.ease["in-out"],U=useSharedValue(D?1:0),[W,Y]=useState(null);useEffect(()=>{const e=D?1:0;return U.value=z?e:withTiming(e,{duration:H,easing:ReanimatedEasing.bezier(...$)}),()=>cancelAnimation(U)},[D,z,U,H,$]);const Z=useCallback(e=>{const t=Math.ceil(e);Y(e=>e===t?e:t)},[]),q=useAnimatedStyle(()=>({paddingHorizontal:G*(1-U.value)})),Q=useAnimatedStyle(()=>{const e=Math.max(0,1-2*U.value);return null===W?U.value>=1?{opacity:e,width:0}:{opacity:e}:{opacity:e,width:(W+M)*(1-U.value)}}),X=u?x.colors["surface-disabled"]:toneBackground(x,a),J=u?x.colors["text-disabled"]:toneForeground(x,a),K=d?_jsx(Spinner,{variant:"circular",size:"lg"===r?"md":"sm",color:J}):renderSlotIcon(o,{color:J,size:v.icon,disabled:u}),ee=useMemo(()=>{if(!l)return null;const e=(c??B)+_.bottom;switch(l){case"bottomLeft":return{position:"absolute",bottom:e,left:T};case"bottomCenter":return{position:"absolute",bottom:e,alignSelf:"center"};default:return{position:"absolute",bottom:e,right:T}}},[l,c,_.bottom,B,T]);return _jsx(Animated.View,{style:[ee,{transform:[{translateY:O},{scale:E}],opacity:L},y,h],pointerEvents:m&&p?"none":"auto",children:_jsx(Pressable,{ref:t,onPress:e=>{if(!w)return;const t=resolveHaptic(f,"impactLight");t&&triggerHaptic(t),n()},onPressIn:F,onPressOut:C,disabled:!w,accessibilityRole:"button",accessibilityLabel:b,accessibilityHint:g,accessibilityState:{disabled:!w,busy:d},"aria-disabled":!w,"aria-busy":d,testID:S,style:[I.base,N?{height:v.diameter,minWidth:v.diameter,borderRadius:v.diameter/2,...smoothCorners}:{width:v.diameter,height:v.diameter,borderRadius:v.diameter/2,...smoothCorners},x.shadow.popover,{backgroundColor:X,opacity:u||d?.55:1}],children:({pressed:e})=>_jsxs(_Fragment,{children:[e&&w?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[I.pressedTint,{backgroundColor:pressedTintFor(x,a),borderRadius:v.diameter/2,...smoothCorners}]}):null,N?_jsxs(Reanimated.View,{style:[I.extendedRow,q],children:[K,_jsx(Reanimated.View,{style:[I.labelClip,Q],children:_jsx(Text,{onLayout:e=>Z(e.nativeEvent.layout.width),style:[I.label,{color:J,fontSize:v.text,fontWeight:x.weight.semibold,marginLeft:M},A],numberOfLines:1,children:i})})]}):K]})})})});FloatingActionButton.displayName="FloatingActionButton";const buildStyles=e=>StyleSheet.create({base:{flexDirection:"row",alignItems:"center",justifyContent:"center",overflow:"hidden"},pressedTint:{position:"absolute",top:0,right:0,bottom:0,left:0},extendedRow:{flexDirection:"row",alignItems:"center"},labelClip:{flexDirection:"row",overflow:"hidden"},label:{includeFontPadding:!1,flexShrink:0}}),FAB_GROUP_MIN_ACTIONS=2,FAB_GROUP_MAX_ACTIONS=6,FAB_GROUP_RANGE="2 to 6",describeActionProblem=e=>e.length<2?`was given ${e.length} action(s); a menu holds 2 to 6.`:e.length>6?`was given ${e.length} actions; a menu holds 2 to 6, so only the first 6 are drawn.`:e.some(e=>"string"!=typeof e.label||""===e.label.trim())?"has an action without a visible `label`; every menu action needs one.":"";export const DEFAULT_FLOATING_ACTION_BUTTON_GROUP_LABELS={quickActions:"Quick actions",expanded:(e,t)=>`${e}, expanded, ${t} ${1===t?"action":"actions"}`,collapsed:e=>`${e}, collapsed`};const FloatingActionButtonGroup=e=>{const{primaryIcon:t,primaryActiveIcon:o,actions:n,expanded:i,defaultExpanded:s=!1,onExpandedChange:r,labels:a,position:l="bottomRight",bottomOffset:c,size:u="md",accessibilityLabel:d,haptic:m,hideOnScroll:p=!1,isScrolling:b=!1,containerStyle:g,secondaryActionStyle:f,labelPillStyle:h,labelStyle:y,testID:A}=e;warnInvalidValue("FloatingActionButtonGroup","size",e.size,FAB_SIZES),warnInvalidValue("FloatingActionButtonGroup","position",e.position,FAB_POSITIONS);const S=useMemo(()=>({...DEFAULT_FLOATING_ACTION_BUTTON_GROUP_LABELS,...a}),[a]),w=d??S.quickActions,x=useTheme(),_=useSafeAreaInsets(),v=useMemo(()=>resolveFloatingActionButtonSize(x,u),[x,u]),I=useMemo(()=>buildGroupStyles(x),[x]),E=usePresenceMotion(),R=E.duration("default"),F=x.space[x.components["floating-action-button"]["edge-offset"]],C=x.space[x.components["floating-action-button"]["bottom-offset"]],j=x.space[x.components["floating-action-button"]["secondary-gap"]],T=x.components["floating-action-button"]["stagger-ms"],B=useMemo(()=>n.slice(0,6),[n]),P=B.length,V=useMemo(()=>B.map((e,t)=>({action:e,index:t})).reverse(),[B]);n.forEach(e=>{warnInvalidValue("FloatingActionButtonGroup","actions[].tone",e.tone,FAB_TONES)});const k=__DEV__?describeActionProblem(n):"";useEffect(()=>{__DEV__&&k&&Logger.warn(`[@webority/mobile-ui] FloatingActionButtonGroup ${k}`)},[k]);const O="boolean"==typeof i,[L,N]=useState(s),D=O?i:L,z=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(!p)return void setNativeValue(z,1);const e=Animated.timing(z,{toValue:b?0:1,duration:R,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:!0});return e.start(),()=>e.stop()},[p,b,z,R,x.motion.ease["in-out"]]);const M=p&&b;useEffect(()=>{M&&D&&(O||N(!1),r?.(!1))},[M,D,O,r]);const G=v.diameter+(c??C)+_.bottom+F,H=z.interpolate({inputRange:[0,1],outputRange:E.range(G,0)}),$=z,U=useRef(createAnimatedValue(D?1:0)).current,W=useRef([]),[Y,Z]=useState(0);useEffect(()=>{const e=W.current;if(e.length!==P){if(e.length<P){const t=e.slice();for(let o=e.length;o<P;o+=1)t.push(new Animated.Value(D?1:0));W.current=t}else W.current=e.slice(0,P);Z(e=>e+1)}},[P]),useEffect(()=>{const e=Animated.timing(U,{toValue:D?1:0,duration:R,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:!0});e.start();const t=W.current.map(e=>Animated.timing(e,{toValue:D?1:0,duration:R,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:!0})),o=D?t:[...t].reverse(),n=Animated.stagger(T,o);return n.start(),()=>{e.stop(),n.stop()}},[D,U,R,x.motion.ease["in-out"],P,Y,T]);const q=useCallback(e=>{const t=resolveHaptic(m,"impactLight");t&&triggerHaptic(t),O||N(e),r?.(e)},[O,r,m]),Q=useRef(null),X=useRef(D),J=useRef(!1);useEffect(()=>{if(X.current===D)return;X.current=D;const e=J.current;if(J.current=!1,M||e)return;const t=Q.current;t&&("web"===Platform.OS?t.focus?.():AccessibilityInfo.sendAccessibilityEvent(t,"focus")),announce(D?S.expanded(w,P):S.collapsed(w))},[D,M,w,P,S]);const K=useCallback(()=>{q(!D)},[D,q]),ee=useCallback(e=>{!1!==m&&triggerHaptic("selection"),J.current=!0,e.onPress(),O||N(!1),r?.(!1)},[O,r,m]),te=useCallback(()=>{D&&q(!1)},[D,q]);useEffect(()=>{if(!D)return;const e=BackHandler.addEventListener("hardwareBackPress",()=>(q(!1),!0));return()=>e.remove()},[D,q]),useEffect(()=>{if(!D||"web"!==Platform.OS)return;const onKeyDown=e=>{"Escape"===e.key&&q(!1)};return window.addEventListener("keydown",onKeyDown),()=>window.removeEventListener("keydown",onKeyDown)},[D,q]);const oe=useMemo(()=>{const e=(c??C)+_.bottom;switch(l){case"bottomLeft":return{position:"absolute",bottom:e,left:F,alignItems:"flex-start"};case"bottomCenter":return{position:"absolute",bottom:e,alignSelf:"center",alignItems:"center"};default:return{position:"absolute",bottom:e,right:F,alignItems:"flex-end"}}},[l,c,_.bottom,C,F]),slotOffset=e=>-(v.diameter+j)*(e+1),ne=useMemo(()=>{switch(l){case"bottomLeft":return{left:0,right:0,justifyContent:"flex-start"};case"bottomCenter":return{left:0,right:0,justifyContent:"center"};default:return{left:0,right:0,justifyContent:"flex-end"}}},[l]),ie=.78*v.diameter,se=useMemo(()=>{const e=ie+x.space.sm;switch(l){case"bottomLeft":return{left:e,alignItems:"flex-start"};case"bottomCenter":return{right:v.diameter/2+ie/2+x.space.sm,alignItems:"flex-end"};default:return{right:e,alignItems:"flex-end"}}},[l,ie,v.diameter,x.space.sm]),re=U.interpolate({inputRange:[0,1],outputRange:[0,.4]}),ae=U.interpolate(E.reduced?{inputRange:[0,.5,.5001,1],outputRange:["0deg","0deg","45deg","45deg"]}:{inputRange:[0,1],outputRange:["0deg","45deg"]});return _jsxs(_Fragment,{children:[D?_jsx(Animated.View,{pointerEvents:D?"auto":"none",style:[StyleSheet.absoluteFill,{backgroundColor:x.colors.scrim,opacity:re}],children:_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:te,accessibilityElementsHidden:!0,importantForAccessibility:"no",testID:A?`${A}-backdrop`:void 0})}):null,_jsxs(Animated.View,{pointerEvents:M?"none":"box-none",style:[oe,{transform:[{translateY:H}],opacity:$},g],accessibilityRole:"menu",testID:A,children:[V.map(({action:e,index:t})=>{const o=W.current[t];if(!o)return null;const n=o.interpolate({inputRange:[0,1],outputRange:E.range(0,slotOffset(t))}),i=o.interpolate({inputRange:[0,1],outputRange:E.range(.6,1)}),s=toneBackground(x,e.tone??"primary"),r=toneForeground(x,e.tone??"primary"),a=e.label?_jsx(View,{pointerEvents:"none",style:[I.labelSlot,se],testID:A?`${A}-label-${e.key}`:void 0,children:_jsx(View,{style:[I.labelPill,x.shadow.card,{backgroundColor:x.colors.surface,paddingHorizontal:x.space.sm,paddingVertical:x.space.xs,borderRadius:x.radius.sm,...smoothCorners},h],children:_jsx(Text,{style:[{color:x.colors["text-body"],fontSize:x.text.sm.size,fontWeight:x.weight.medium},y],numberOfLines:1,children:e.label})})}):null;return _jsxs(Animated.View,{pointerEvents:D?"auto":"none",accessibilityElementsHidden:!D,importantForAccessibility:D?"auto":"no-hide-descendants","aria-hidden":!D,style:[I.secondaryRow,ne,{position:"absolute",bottom:0,opacity:o,transform:[{translateY:n},{scale:i}]}],children:[_jsx(Pressable,{onPress:()=>ee(e),focusable:D,accessibilityRole:"menuitem",accessibilityLabel:e.accessibilityLabel,style:[I.fabBase,x.shadow.elevated,{width:ie,height:ie,borderRadius:ie/2,...smoothCorners,backgroundColor:s},f],testID:A?`${A}-action-${e.key}`:void 0,children:({pressed:t})=>_jsxs(_Fragment,{children:[t?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[I.pressedTint,{backgroundColor:pressedTintFor(x,e.tone??"primary"),borderRadius:ie/2,...smoothCorners}]}):null,renderSlotIcon(e.icon,{color:r,size:v.icon,disabled:!1})]})}),a]},e.key)}),_jsx(Pressable,{ref:Q,onPress:K,accessibilityRole:"button",accessibilityLabel:w,accessibilityState:{expanded:D},"aria-expanded":D,style:[I.fabBase,x.shadow.popover,{width:v.diameter,height:v.diameter,borderRadius:v.diameter/2,...smoothCorners,backgroundColor:x.colors.primary}],testID:A?`${A}-primary`:void 0,children:({pressed:e})=>_jsxs(_Fragment,{children:[e?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[I.pressedTint,{backgroundColor:ACCENT_PRESSED_TINT,borderRadius:v.diameter/2,...smoothCorners}]}):null,_jsx(Animated.View,{style:o?void 0:{transform:[{rotate:ae}]},children:renderSlotIcon(D&&o?o:t,{color:x.colors["on-primary"],size:v.icon,disabled:!1})})]})})]})]})},buildGroupStyles=e=>StyleSheet.create({fabBase:{flexDirection:"row",alignItems:"center",justifyContent:"center",overflow:"hidden"},pressedTint:{position:"absolute",top:0,right:0,bottom:0,left:0},secondaryRow:{flexDirection:"row",alignItems:"center"},labelSlot:{position:"absolute",top:0,bottom:0,justifyContent:"center"},labelPill:{alignSelf:"auto"}});export{FloatingActionButton,FloatingActionButtonGroup};export default FloatingActionButton;
|
|
1
|
+
"use strict";import{Logger}from"@webority/mobile-core";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Animated,BackHandler,Easing,Platform,Pressable,StyleSheet,Text,View}from"react-native";import Reanimated,{cancelAnimation,Easing as ReanimatedEasing,useAnimatedStyle,useSharedValue,withTiming}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{usePressAnimation}from"../../hooks/usePressAnimation.js";import{createAnimatedValue,resolveFloatingActionButtonSize,setNativeValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{ACCENT_PRESSED_TINT}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const FAB_SIZES=["sm","md","lg"],FAB_TONES=["primary","success","warning","danger","info","neutral"],FAB_POSITIONS=["bottomRight","bottomLeft","bottomCenter"],toneBackground=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors["bg-muted"];default:return e.colors.primary}},pressedTintFor=(e,t)=>"neutral"===t?e.colors["surface-pressed"]:ACCENT_PRESSED_TINT,toneForeground=(e,t)=>{if("neutral"===t)return e.colors["text-body"];switch(t){case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];default:return e.colors["on-primary"]}},FloatingActionButton=forwardRef((e,t)=>{const{icon:o,onPress:n,label:i,collapsed:s=!1,size:r="md",tone:a="primary",position:l,bottomOffset:c,disabled:u=!1,loading:d=!1,hideOnScroll:m=!1,isScrolling:p=!1,accessibilityLabel:b,accessibilityHint:g,haptic:f,style:h,containerStyle:y,labelStyle:A,testID:S}=e;warnInvalidValue("FloatingActionButton","size",e.size,FAB_SIZES),warnInvalidValue("FloatingActionButton","tone",e.tone,FAB_TONES),warnInvalidValue("FloatingActionButton","position",e.position,FAB_POSITIONS);const w=!u&&!d,x=useTheme(),_=useSafeAreaInsets(),v=useMemo(()=>resolveFloatingActionButtonSize(x,r),[x,r]),I=useMemo(()=>buildStyles(x),[x]),{scale:E,opacity:R,pressIn:F,pressOut:C}=usePressAnimation({enabled:w}),j=usePresenceMotion(),T=x.space[x.components["floating-action-button"]["edge-offset"]],B=x.space[x.components["floating-action-button"]["bottom-offset"]],P=useRef(createAnimatedValue(1)).current,V=j.duration("default");useEffect(()=>{if(!m)return void setNativeValue(P,1);const e=Animated.timing(P,{toValue:p?0:1,duration:V,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:!0});return e.start(),()=>e.stop()},[m,p,P,V,x.motion.ease["in-out"]]);const k=v.diameter+(c??B)+_.bottom+T,O=P.interpolate({inputRange:[0,1],outputRange:j.range(k,0)}),L=useMemo(()=>Animated.multiply(P,R),[P,R]),N="string"==typeof i&&i.length>0,D=N&&s,z=j.reduced,M=x.space.sm,G=v["label-padding-x"],H=x.motion.duration.fast,$=x.motion.ease["in-out"],U=useSharedValue(D?1:0),[W,Y]=useState(null);useEffect(()=>{const e=D?1:0;return U.value=z?e:withTiming(e,{duration:H,easing:ReanimatedEasing.bezier(...$)}),()=>cancelAnimation(U)},[D,z,U,H,$]);const Z=useCallback(e=>{const t=Math.ceil(e);Y(e=>e===t?e:t)},[]),q=useAnimatedStyle(()=>({paddingHorizontal:G*(1-U.value)}),[G,U]),Q=useAnimatedStyle(()=>{const e=Math.max(0,1-2*U.value);return null===W?U.value>=1?{opacity:e,width:0}:{opacity:e}:{opacity:e,width:(W+M)*(1-U.value)}},[U,W,M]),X=u?x.colors["surface-disabled"]:toneBackground(x,a),J=u?x.colors["text-disabled"]:toneForeground(x,a),K=d?_jsx(Spinner,{variant:"circular",size:"lg"===r?"md":"sm",color:J}):renderSlotIcon(o,{color:J,size:v.icon,disabled:u}),ee=useMemo(()=>{if(!l)return null;const e=(c??B)+_.bottom;switch(l){case"bottomLeft":return{position:"absolute",bottom:e,left:T};case"bottomCenter":return{position:"absolute",bottom:e,alignSelf:"center"};default:return{position:"absolute",bottom:e,right:T}}},[l,c,_.bottom,B,T]);return _jsx(Animated.View,{style:[ee,{transform:[{translateY:O},{scale:E}],opacity:L},y,h],pointerEvents:m&&p?"none":"auto",children:_jsx(Pressable,{ref:t,onPress:e=>{if(!w)return;const t=resolveHaptic(f,"impactLight");t&&triggerHaptic(t),n()},onPressIn:F,onPressOut:C,disabled:!w,accessibilityRole:"button",accessibilityLabel:b,accessibilityHint:g,accessibilityState:{disabled:!w,busy:d},"aria-disabled":!w,"aria-busy":d,testID:S,style:[I.base,N?{height:v.diameter,minWidth:v.diameter,borderRadius:v.diameter/2,...smoothCorners}:{width:v.diameter,height:v.diameter,borderRadius:v.diameter/2,...smoothCorners},x.shadow.popover,{backgroundColor:X,opacity:u||d?.55:1}],children:({pressed:e})=>_jsxs(_Fragment,{children:[e&&w?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[I.pressedTint,{backgroundColor:pressedTintFor(x,a),borderRadius:v.diameter/2,...smoothCorners}]}):null,N?_jsxs(Reanimated.View,{style:[I.extendedRow,q],children:[K,_jsx(Reanimated.View,{style:[I.labelClip,Q],children:_jsx(Text,{onLayout:e=>Z(e.nativeEvent.layout.width),style:[I.label,{color:J,fontSize:v.text,fontWeight:x.weight.semibold,marginLeft:M},A],numberOfLines:1,children:i})})]}):K]})})})});FloatingActionButton.displayName="FloatingActionButton";const buildStyles=e=>StyleSheet.create({base:{flexDirection:"row",alignItems:"center",justifyContent:"center",overflow:"hidden"},pressedTint:{position:"absolute",top:0,right:0,bottom:0,left:0},extendedRow:{flexDirection:"row",alignItems:"center"},labelClip:{flexDirection:"row",overflow:"hidden"},label:{includeFontPadding:!1,flexShrink:0}}),FAB_GROUP_MIN_ACTIONS=2,FAB_GROUP_MAX_ACTIONS=6,FAB_GROUP_RANGE="2 to 6",describeActionProblem=e=>e.length<2?`was given ${e.length} action(s); a menu holds 2 to 6.`:e.length>6?`was given ${e.length} actions; a menu holds 2 to 6, so only the first 6 are drawn.`:e.some(e=>"string"!=typeof e.label||""===e.label.trim())?"has an action without a visible `label`; every menu action needs one.":"";export const DEFAULT_FLOATING_ACTION_BUTTON_GROUP_LABELS={quickActions:"Quick actions",expanded:(e,t)=>`${e}, expanded, ${t} ${1===t?"action":"actions"}`,collapsed:e=>`${e}, collapsed`};const FloatingActionButtonGroup=e=>{const{primaryIcon:t,primaryActiveIcon:o,actions:n,expanded:i,defaultExpanded:s=!1,onExpandedChange:r,labels:a,position:l="bottomRight",bottomOffset:c,size:u="md",accessibilityLabel:d,haptic:m,hideOnScroll:p=!1,isScrolling:b=!1,containerStyle:g,secondaryActionStyle:f,labelPillStyle:h,labelStyle:y,testID:A}=e;warnInvalidValue("FloatingActionButtonGroup","size",e.size,FAB_SIZES),warnInvalidValue("FloatingActionButtonGroup","position",e.position,FAB_POSITIONS);const S=useMemo(()=>({...DEFAULT_FLOATING_ACTION_BUTTON_GROUP_LABELS,...a}),[a]),w=d??S.quickActions,x=useTheme(),_=useSafeAreaInsets(),v=useMemo(()=>resolveFloatingActionButtonSize(x,u),[x,u]),I=useMemo(()=>buildGroupStyles(x),[x]),E=usePresenceMotion(),R=E.duration("default"),F=x.space[x.components["floating-action-button"]["edge-offset"]],C=x.space[x.components["floating-action-button"]["bottom-offset"]],j=x.space[x.components["floating-action-button"]["secondary-gap"]],T=x.components["floating-action-button"]["stagger-ms"],B=useMemo(()=>n.slice(0,6),[n]),P=B.length,V=useMemo(()=>B.map((e,t)=>({action:e,index:t})).reverse(),[B]);n.forEach(e=>{warnInvalidValue("FloatingActionButtonGroup","actions[].tone",e.tone,FAB_TONES)});const k=__DEV__?describeActionProblem(n):"";useEffect(()=>{__DEV__&&k&&Logger.warn(`[@webority/mobile-ui] FloatingActionButtonGroup ${k}`)},[k]);const O="boolean"==typeof i,[L,N]=useState(s),D=O?i:L,z=useRef(createAnimatedValue(1)).current;useEffect(()=>{if(!p)return void setNativeValue(z,1);const e=Animated.timing(z,{toValue:b?0:1,duration:R,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:!0});return e.start(),()=>e.stop()},[p,b,z,R,x.motion.ease["in-out"]]);const M=p&&b;useEffect(()=>{M&&D&&(O||N(!1),r?.(!1))},[M,D,O,r]);const G=v.diameter+(c??C)+_.bottom+F,H=z.interpolate({inputRange:[0,1],outputRange:E.range(G,0)}),$=z,U=useRef(createAnimatedValue(D?1:0)).current,W=useRef([]),[Y,Z]=useState(0);useEffect(()=>{const e=W.current;if(e.length!==P){if(e.length<P){const t=e.slice();for(let o=e.length;o<P;o+=1)t.push(new Animated.Value(D?1:0));W.current=t}else W.current=e.slice(0,P);Z(e=>e+1)}},[P]),useEffect(()=>{const e=Animated.timing(U,{toValue:D?1:0,duration:R,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:!0});e.start();const t=W.current.map(e=>Animated.timing(e,{toValue:D?1:0,duration:R,easing:Easing.bezier(...x.motion.ease["in-out"]),useNativeDriver:!0})),o=D?t:[...t].reverse(),n=Animated.stagger(T,o);return n.start(),()=>{e.stop(),n.stop()}},[D,U,R,x.motion.ease["in-out"],P,Y,T]);const q=useCallback(e=>{const t=resolveHaptic(m,"impactLight");t&&triggerHaptic(t),O||N(e),r?.(e)},[O,r,m]),Q=useRef(null),X=useRef(D),J=useRef(!1);useEffect(()=>{if(X.current===D)return;X.current=D;const e=J.current;if(J.current=!1,M||e)return;const t=Q.current;t&&("web"===Platform.OS?t.focus?.():AccessibilityInfo.sendAccessibilityEvent(t,"focus")),announce(D?S.expanded(w,P):S.collapsed(w))},[D,M,w,P,S]);const K=useCallback(()=>{q(!D)},[D,q]),ee=useCallback(e=>{!1!==m&&triggerHaptic("selection"),J.current=!0,e.onPress(),O||N(!1),r?.(!1)},[O,r,m]),te=useCallback(()=>{D&&q(!1)},[D,q]);useEffect(()=>{if(!D)return;const e=BackHandler.addEventListener("hardwareBackPress",()=>(q(!1),!0));return()=>e.remove()},[D,q]),useEffect(()=>{if(!D||"web"!==Platform.OS)return;const onKeyDown=e=>{"Escape"===e.key&&q(!1)};return window.addEventListener("keydown",onKeyDown),()=>window.removeEventListener("keydown",onKeyDown)},[D,q]);const oe=useMemo(()=>{const e=(c??C)+_.bottom;switch(l){case"bottomLeft":return{position:"absolute",bottom:e,left:F,alignItems:"flex-start"};case"bottomCenter":return{position:"absolute",bottom:e,alignSelf:"center",alignItems:"center"};default:return{position:"absolute",bottom:e,right:F,alignItems:"flex-end"}}},[l,c,_.bottom,C,F]),slotOffset=e=>-(v.diameter+j)*(e+1),ne=useMemo(()=>{switch(l){case"bottomLeft":return{left:0,right:0,justifyContent:"flex-start"};case"bottomCenter":return{left:0,right:0,justifyContent:"center"};default:return{left:0,right:0,justifyContent:"flex-end"}}},[l]),ie=.78*v.diameter,se=useMemo(()=>{const e=ie+x.space.sm;switch(l){case"bottomLeft":return{left:e,alignItems:"flex-start"};case"bottomCenter":return{right:v.diameter/2+ie/2+x.space.sm,alignItems:"flex-end"};default:return{right:e,alignItems:"flex-end"}}},[l,ie,v.diameter,x.space.sm]),re=U.interpolate({inputRange:[0,1],outputRange:[0,.4]}),ae=U.interpolate(E.reduced?{inputRange:[0,.5,.5001,1],outputRange:["0deg","0deg","45deg","45deg"]}:{inputRange:[0,1],outputRange:["0deg","45deg"]});return _jsxs(_Fragment,{children:[D?_jsx(Animated.View,{pointerEvents:D?"auto":"none",style:[StyleSheet.absoluteFill,{backgroundColor:x.colors.scrim,opacity:re}],children:_jsx(Pressable,{style:StyleSheet.absoluteFill,onPress:te,accessibilityElementsHidden:!0,importantForAccessibility:"no",testID:A?`${A}-backdrop`:void 0})}):null,_jsxs(Animated.View,{pointerEvents:M?"none":"box-none",style:[oe,{transform:[{translateY:H}],opacity:$},g],accessibilityRole:"menu",testID:A,children:[V.map(({action:e,index:t})=>{const o=W.current[t];if(!o)return null;const n=o.interpolate({inputRange:[0,1],outputRange:E.range(0,slotOffset(t))}),i=o.interpolate({inputRange:[0,1],outputRange:E.range(.6,1)}),s=toneBackground(x,e.tone??"primary"),r=toneForeground(x,e.tone??"primary"),a=e.label?_jsx(View,{pointerEvents:"none",style:[I.labelSlot,se],testID:A?`${A}-label-${e.key}`:void 0,children:_jsx(View,{style:[I.labelPill,x.shadow.card,{backgroundColor:x.colors.surface,paddingHorizontal:x.space.sm,paddingVertical:x.space.xs,borderRadius:x.radius.sm,...smoothCorners},h],children:_jsx(Text,{style:[{color:x.colors["text-body"],fontSize:x.text.sm.size,fontWeight:x.weight.medium},y],numberOfLines:1,children:e.label})})}):null;return _jsxs(Animated.View,{pointerEvents:D?"auto":"none",accessibilityElementsHidden:!D,importantForAccessibility:D?"auto":"no-hide-descendants","aria-hidden":!D,style:[I.secondaryRow,ne,{position:"absolute",bottom:0,opacity:o,transform:[{translateY:n},{scale:i}]}],children:[_jsx(Pressable,{onPress:()=>ee(e),focusable:D,accessibilityRole:"menuitem",accessibilityLabel:e.accessibilityLabel,style:[I.fabBase,x.shadow.elevated,{width:ie,height:ie,borderRadius:ie/2,...smoothCorners,backgroundColor:s},f],testID:A?`${A}-action-${e.key}`:void 0,children:({pressed:t})=>_jsxs(_Fragment,{children:[t?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[I.pressedTint,{backgroundColor:pressedTintFor(x,e.tone??"primary"),borderRadius:ie/2,...smoothCorners}]}):null,renderSlotIcon(e.icon,{color:r,size:v.icon,disabled:!1})]})}),a]},e.key)}),_jsx(Pressable,{ref:Q,onPress:K,accessibilityRole:"button",accessibilityLabel:w,accessibilityState:{expanded:D},"aria-expanded":D,style:[I.fabBase,x.shadow.popover,{width:v.diameter,height:v.diameter,borderRadius:v.diameter/2,...smoothCorners,backgroundColor:x.colors.primary}],testID:A?`${A}-primary`:void 0,children:({pressed:e})=>_jsxs(_Fragment,{children:[e?_jsx(View,{pointerEvents:"none",testID:"fab-pressed",style:[I.pressedTint,{backgroundColor:ACCENT_PRESSED_TINT,borderRadius:v.diameter/2,...smoothCorners}]}):null,_jsx(Animated.View,{style:o?void 0:{transform:[{rotate:ae}]},children:renderSlotIcon(D&&o?o:t,{color:x.colors["on-primary"],size:v.icon,disabled:!1})})]})})]})]})},buildGroupStyles=e=>StyleSheet.create({fabBase:{flexDirection:"row",alignItems:"center",justifyContent:"center",overflow:"hidden"},pressedTint:{position:"absolute",top:0,right:0,bottom:0,left:0},secondaryRow:{flexDirection:"row",alignItems:"center"},labelSlot:{position:"absolute",top:0,bottom:0,justifyContent:"center"},labelPill:{alignSelf:"auto"}});export{FloatingActionButton,FloatingActionButtonGroup};export default FloatingActionButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import React,{useCallback,useMemo,useRef,useState}from"react";import{Dimensions,Image,Pressable,StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Carousel}from"../Carousel/index.js";import{Modal}from"../Modal/Modal.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_IMAGE_GALLERY_LABELS={gallery:"Image gallery",imageOf:(e,t)=>`Image ${e} of ${t}`,openFullscreen:"Tap to open fullscreen",closeGallery:"Close gallery"};const MAX_SCALE_FALLBACK=4,MIN_SCALE_FALLBACK=1,DOUBLE_TAP_SCALE_FALLBACK=2,SPRING_CONFIG={damping:18,stiffness:220,mass:1},ImageGallery=({images:e,initialIndex:t=0,showThumbnails:a=!0,showCounter:l=!0,enableLightbox:i=!0,enablePinchZoom:s=!0,onIndexChange:o,haptic:n,loading:r=!1,accessibilityLabel:c,containerStyle:u,testID:m,labels:d})=>{const h=useTheme(),g=useMemo(()=>buildStyles(h),[h]),p=useMemo(()=>({...DEFAULT_IMAGE_GALLERY_LABELS,...d}),[d]),[b,S]=useState(clamp(t,0,Math.max(0,e.length-1))),[x,y]=useState(!1),v=useCallback(e=>{S(e),o?.(e)},[o]),I=useCallback(()=>{if(!i)return;const e=resolveHaptic(n,"selection");e&&triggerHaptic(e),y(!0)},[i,n]),w=useCallback(()=>{const e=resolveHaptic(n,"selection");e&&triggerHaptic(e),y(!1)},[n]),C=useCallback((t,a)=>{const l=t.alt??p.imageOf(a+1,e.length);return _jsx(Pressable,{onPress:I,accessibilityRole:"image",accessibilityLabel:l,accessibilityHint:i?p.openFullscreen:void 0,style:g.imageWrap,children:_jsx(Image,{source:t.source,style:g.image,resizeMode:"cover"})})},[i,e.length,I,g,p]),_=useCallback(e=>_jsx(Image,{source:e.source,style:g.thumbnailImage,resizeMode:"cover"}),[g]),f=_jsxs(View,{style:[g.container,u],testID:m,accessibilityLabel:c??p.gallery,children:[_jsxs(View,{style:g.carouselWrap,accessibilityElementsHidden:x,importantForAccessibility:x?"no-hide-descendants":"auto",children:[_jsx(Carousel,{data:e,defaultIndex:t,onIndexChange:v,renderItem:C,showPagination:!1,showThumbnails:a,renderThumbnail:_,haptic:n}),l&&e.length>0?_jsx(View,{style:g.counterPill,pointerEvents:"none",children:_jsx(Text,{variant:"label",weight:"semibold",style:{color:h.colors["on-scrim"]},accessibilityLabel:p.imageOf(b+1,e.length),children:`${b+1} / ${e.length}`})}):null]}),i?_jsx(Lightbox,{open:x,images:e,initialIndex:b,enablePinchZoom:s,showCounter:l,onClose:w,onIndexChange:v,haptic:n,labels:p}):null]});return r?_jsx(ImageGallerySkeleton,{images:e,showThumbnails:a,showCounter:l,containerStyle:u,testID:m}):f};ImageGallery.displayName="ImageGallery";const ImageGallerySkeleton=({images:e,showThumbnails:t=!0,showCounter:a=!0,containerStyle:l,testID:i})=>{const s=useTheme(),o=Math.min(e?.length||4,6);return _jsxs(View,{style:[{width:"100%"},l],testID:i,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[_jsxs(View,{style:{position:"relative"},children:[_jsx(Skeleton,{width:"100%",height:280,radius:"lg"}),a?_jsx(View,{style:{position:"absolute",top:12,right:12},children:_jsx(Skeleton,{width:44,height:22,radius:"pill"})}):null]}),t?_jsx(View,{style:{flexDirection:"row",marginTop:s.space.md},children:Array.from({length:o}).map((e,t)=>_jsx(Skeleton,{width:64,height:64,radius:"md",style:{marginRight:s.space.sm}},`sk-thumb-${t}`))}):null]})};ImageGallerySkeleton.displayName="ImageGallerySkeleton",ImageGallery.Skeleton=ImageGallerySkeleton;const Lightbox=({open:e,images:t,initialIndex:a,enablePinchZoom:l,showCounter:i,onClose:s,onIndexChange:o,haptic:n,labels:r})=>{const c=useTheme(),u=useMemo(()=>buildLightboxStyles(c),[c]),m=useRef(null),[d,h]=useState(a),g=useCallback(e=>{if(e!==d){const t=resolveHaptic(n,"selection");t&&triggerHaptic(t),h(e),o(e)}},[d,o,n]),p=useCallback((e,a)=>_jsx(ZoomableImage,{image:e,index:a,total:t.length,active:a===d,enabled:l,maxScale:4,minScale:1,doubleTapScale:2,haptic:n,imageLabel:r.imageOf}),[d,l,t.length,n,r]),b=t[d]?.caption;return _jsx(Modal,{open:e,onClose:s,presentation:"fullScreen",backdropPressClose:!1,animateMount:!1,contentStyle:{backgroundColor:"transparent"},children:_jsxs(View,{style:u.backdrop,children:[_jsx(Carousel,{ref:m,data:t,defaultIndex:a,onIndexChange:g,renderItem:p,showPagination:!1,haptic:n}),i&&t.length>0?_jsx(View,{style:u.counterPill,pointerEvents:"none",children:_jsx(Text,{variant:"label",weight:"semibold",style:{color:c.colors["on-scrim"]},accessibilityLabel:r.imageOf(d+1,t.length),children:`${d+1} / ${t.length}`})}):null,_jsx(Pressable,{onPress:s,accessibilityRole:"button",accessibilityLabel:r.closeGallery,style:u.closeButton,hitSlop:12,...hitSlopMarker(12),children:(c.settings.icons.close??defaultIcons.close)({size:24,color:c.colors["on-scrim"]})}),b?_jsx(Animated.View,{style:u.captionWrap,entering:void 0,accessibilityElementsHidden:!1,children:_jsx(Text,{variant:"body",align:"center",numberOfLines:3,style:u.captionText,children:b})}):null]})})},ZoomableImage=({image:e,index:t,total:a,active:l,enabled:i,maxScale:s,minScale:o,doubleTapScale:n,haptic:r,imageLabel:c})=>{const u=Dimensions.get("window"),m=useSharedValue(1),d=useSharedValue(1),h=useSharedValue(0),g=useSharedValue(0),p=useSharedValue(0),b=useSharedValue(0),S=useCallback(()=>{m.value=withSpring(1,SPRING_CONFIG),d.value=1,h.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),p.value=0,b.value=0},[m,d,h,g,p,b]);React.useEffect(()=>{l||(m.value=withTiming(1,{duration:150}),h.value=withTiming(0,{duration:150}),g.value=withTiming(0,{duration:150}),d.value=1,p.value=0,b.value=0)},[l,m,h,g,d,p,b]);const x=useCallback(()=>{!1!==r&&triggerHaptic("impactLight")},[r]),y=useMemo(()=>Gesture.Pinch().enabled(i).onStart(()=>{"worklet";d.value=m.value}).onUpdate(e=>{"worklet";const t=d.value*e.scale;m.value=t<o?o+.3*(t-o):t>s?s+.2*(t-s):t}).onEnd(()=>{"worklet";return m.value<o?(m.value=withSpring(o,SPRING_CONFIG),h.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),d.value=o,p.value=0,void(b.value=0)):m.value>s?(m.value=withSpring(s,SPRING_CONFIG),void(d.value=s)):void(d.value=m.value)}),[i,m,d,h,g,p,b,o,s]),v=useMemo(()=>Gesture.Pan().minPointers(1).maxPointers(1).onStart(()=>{"worklet";p.value=h.value,b.value=g.value}).onUpdate(e=>{"worklet";m.value<=1||(h.value=p.value+e.translationX,g.value=b.value+e.translationY)}).onEnd(()=>{"worklet";p.value=h.value,b.value=g.value}),[m,h,g,p,b]),I=useMemo(()=>Gesture.Tap().numberOfTaps(2).onEnd(()=>{"worklet";runOnJS(x)(),m.value>1?(m.value=withSpring(1,SPRING_CONFIG),h.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),d.value=1,p.value=0,b.value=0):(m.value=withSpring(n,SPRING_CONFIG),d.value=n)}),[m,d,h,g,p,b,x,n]),w=useMemo(()=>Gesture.Race(y,v,I),[y,v,I]),C=useAnimatedStyle(()=>({transform:[{translateX:h.value},{translateY:g.value},{scale:m.value}]}));React.useEffect(()=>{l||S()},[l,S]);const _=e.alt??c(t+1,a);return _jsx(GestureDetector,{gesture:w,children:_jsx(Animated.View,{style:[lightboxImageStyles.container,{width:u.width}],children:_jsx(Animated.Image,{source:e.source,resizeMode:"contain",style:[lightboxImageStyles.image,C],accessibilityLabel:_,accessible:!0})})})},clamp=(e,t,a)=>Math.min(Math.max(e,t),a),buildStyles=e=>StyleSheet.create({container:{width:"100%"},carouselWrap:{width:"100%",position:"relative"},imageWrap:{width:"100%",aspectRatio:16/9,backgroundColor:e.colors["bg-subtle"],overflow:"hidden",borderRadius:e.radius.md,...smoothCorners},image:{width:"100%",height:"100%"},thumbnailImage:{width:"100%",height:"100%"},counterPill:{position:"absolute",top:12,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:"rgba(0,0,0,0.55)"}}),buildLightboxStyles=e=>StyleSheet.create({backdrop:{flex:1,backgroundColor:"#000",justifyContent:"center"},counterPill:{position:"absolute",top:48,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:"rgba(0,0,0,0.6)"},closeButton:{position:"absolute",top:44,right:16,width:40,height:40,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},captionWrap:{position:"absolute",left:0,right:0,bottom:32,paddingHorizontal:e.space.xl},captionText:{color:e.colors["on-scrim"],lineHeight:21}}),lightboxImageStyles=StyleSheet.create({container:{flex:1,alignItems:"center",justifyContent:"center"},image:{width:"100%",height:"100%"}});export{ImageGallery};export default ImageGallery;
|
|
1
|
+
"use strict";import React,{useCallback,useMemo,useRef,useState}from"react";import{Dimensions,Image,Pressable,StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{Carousel}from"../Carousel/index.js";import{Modal}from"../Modal/Modal.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_IMAGE_GALLERY_LABELS={gallery:"Image gallery",imageOf:(e,t)=>`Image ${e} of ${t}`,openFullscreen:"Tap to open fullscreen",closeGallery:"Close gallery"};const MAX_SCALE_FALLBACK=4,MIN_SCALE_FALLBACK=1,DOUBLE_TAP_SCALE_FALLBACK=2,SPRING_CONFIG={damping:18,stiffness:220,mass:1},ImageGallery=({images:e,initialIndex:t=0,showThumbnails:a=!0,showCounter:l=!0,enableLightbox:i=!0,enablePinchZoom:s=!0,onIndexChange:o,haptic:n,loading:r=!1,accessibilityLabel:c,containerStyle:u,testID:m,labels:d})=>{const h=useTheme(),g=useMemo(()=>buildStyles(h),[h]),p=useMemo(()=>({...DEFAULT_IMAGE_GALLERY_LABELS,...d}),[d]),[b,S]=useState(clamp(t,0,Math.max(0,e.length-1))),[x,y]=useState(!1),v=useCallback(e=>{S(e),o?.(e)},[o]),I=useCallback(()=>{if(!i)return;const e=resolveHaptic(n,"selection");e&&triggerHaptic(e),y(!0)},[i,n]),w=useCallback(()=>{const e=resolveHaptic(n,"selection");e&&triggerHaptic(e),y(!1)},[n]),C=useCallback((t,a)=>{const l=t.alt??p.imageOf(a+1,e.length);return _jsx(Pressable,{onPress:I,accessibilityRole:"image",accessibilityLabel:l,accessibilityHint:i?p.openFullscreen:void 0,style:g.imageWrap,children:_jsx(Image,{source:t.source,style:g.image,resizeMode:"cover"})})},[i,e.length,I,g,p]),_=useCallback(e=>_jsx(Image,{source:e.source,style:g.thumbnailImage,resizeMode:"cover"}),[g]),f=_jsxs(View,{style:[g.container,u],testID:m,accessibilityLabel:c??p.gallery,children:[_jsxs(View,{style:g.carouselWrap,accessibilityElementsHidden:x,importantForAccessibility:x?"no-hide-descendants":"auto",children:[_jsx(Carousel,{data:e,defaultIndex:t,onIndexChange:v,renderItem:C,showPagination:!1,showThumbnails:a,renderThumbnail:_,haptic:n}),l&&e.length>0?_jsx(View,{style:g.counterPill,pointerEvents:"none",children:_jsx(Text,{variant:"label",weight:"semibold",style:{color:h.colors["on-scrim"]},accessibilityLabel:p.imageOf(b+1,e.length),children:`${b+1} / ${e.length}`})}):null]}),i?_jsx(Lightbox,{open:x,images:e,initialIndex:b,enablePinchZoom:s,showCounter:l,onClose:w,onIndexChange:v,haptic:n,labels:p}):null]});return r?_jsx(ImageGallerySkeleton,{images:e,showThumbnails:a,showCounter:l,containerStyle:u,testID:m}):f};ImageGallery.displayName="ImageGallery";const ImageGallerySkeleton=({images:e,showThumbnails:t=!0,showCounter:a=!0,containerStyle:l,testID:i})=>{const s=useTheme(),o=Math.min(e?.length||4,6);return _jsxs(View,{style:[{width:"100%"},l],testID:i,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[_jsxs(View,{style:{position:"relative"},children:[_jsx(Skeleton,{width:"100%",height:280,radius:"lg"}),a?_jsx(View,{style:{position:"absolute",top:12,right:12},children:_jsx(Skeleton,{width:44,height:22,radius:"pill"})}):null]}),t?_jsx(View,{style:{flexDirection:"row",marginTop:s.space.md},children:Array.from({length:o}).map((e,t)=>_jsx(Skeleton,{width:64,height:64,radius:"md",style:{marginRight:s.space.sm}},`sk-thumb-${t}`))}):null]})};ImageGallerySkeleton.displayName="ImageGallerySkeleton",ImageGallery.Skeleton=ImageGallerySkeleton;const Lightbox=({open:e,images:t,initialIndex:a,enablePinchZoom:l,showCounter:i,onClose:s,onIndexChange:o,haptic:n,labels:r})=>{const c=useTheme(),u=useMemo(()=>buildLightboxStyles(c),[c]),m=useRef(null),[d,h]=useState(a),g=useCallback(e=>{if(e!==d){const t=resolveHaptic(n,"selection");t&&triggerHaptic(t),h(e),o(e)}},[d,o,n]),p=useCallback((e,a)=>_jsx(ZoomableImage,{image:e,index:a,total:t.length,active:a===d,enabled:l,maxScale:4,minScale:1,doubleTapScale:2,haptic:n,imageLabel:r.imageOf}),[d,l,t.length,n,r]),b=t[d]?.caption;return _jsx(Modal,{open:e,onClose:s,presentation:"fullScreen",backdropPressClose:!1,animateMount:!1,contentStyle:{backgroundColor:"transparent"},children:_jsxs(View,{style:u.backdrop,children:[_jsx(Carousel,{ref:m,data:t,defaultIndex:a,onIndexChange:g,renderItem:p,showPagination:!1,haptic:n}),i&&t.length>0?_jsx(View,{style:u.counterPill,pointerEvents:"none",children:_jsx(Text,{variant:"label",weight:"semibold",style:{color:c.colors["on-scrim"]},accessibilityLabel:r.imageOf(d+1,t.length),children:`${d+1} / ${t.length}`})}):null,_jsx(Pressable,{onPress:s,accessibilityRole:"button",accessibilityLabel:r.closeGallery,style:u.closeButton,hitSlop:12,...hitSlopMarker(12),children:(c.settings.icons.close??defaultIcons.close)({size:24,color:c.colors["on-scrim"]})}),b?_jsx(Animated.View,{style:u.captionWrap,entering:void 0,accessibilityElementsHidden:!1,children:_jsx(Text,{variant:"body",align:"center",numberOfLines:3,style:u.captionText,children:b})}):null]})})},ZoomableImage=({image:e,index:t,total:a,active:l,enabled:i,maxScale:s,minScale:o,doubleTapScale:n,haptic:r,imageLabel:c})=>{const u=Dimensions.get("window"),m=useSharedValue(1),d=useSharedValue(1),h=useSharedValue(0),g=useSharedValue(0),p=useSharedValue(0),b=useSharedValue(0),S=useCallback(()=>{m.value=withSpring(1,SPRING_CONFIG),d.value=1,h.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),p.value=0,b.value=0},[m,d,h,g,p,b]);React.useEffect(()=>{l||(m.value=withTiming(1,{duration:150}),h.value=withTiming(0,{duration:150}),g.value=withTiming(0,{duration:150}),d.value=1,p.value=0,b.value=0)},[l,m,h,g,d,p,b]);const x=useCallback(()=>{!1!==r&&triggerHaptic("impactLight")},[r]),y=useMemo(()=>Gesture.Pinch().enabled(i).onStart(()=>{"worklet";d.value=m.value}).onUpdate(e=>{"worklet";const t=d.value*e.scale;m.value=t<o?o+.3*(t-o):t>s?s+.2*(t-s):t}).onEnd(()=>{"worklet";return m.value<o?(m.value=withSpring(o,SPRING_CONFIG),h.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),d.value=o,p.value=0,void(b.value=0)):m.value>s?(m.value=withSpring(s,SPRING_CONFIG),void(d.value=s)):void(d.value=m.value)}),[i,m,d,h,g,p,b,o,s]),v=useMemo(()=>Gesture.Pan().minPointers(1).maxPointers(1).onStart(()=>{"worklet";p.value=h.value,b.value=g.value}).onUpdate(e=>{"worklet";m.value<=1||(h.value=p.value+e.translationX,g.value=b.value+e.translationY)}).onEnd(()=>{"worklet";p.value=h.value,b.value=g.value}),[m,h,g,p,b]),I=useMemo(()=>Gesture.Tap().numberOfTaps(2).onEnd(()=>{"worklet";runOnJS(x)(),m.value>1?(m.value=withSpring(1,SPRING_CONFIG),h.value=withSpring(0,SPRING_CONFIG),g.value=withSpring(0,SPRING_CONFIG),d.value=1,p.value=0,b.value=0):(m.value=withSpring(n,SPRING_CONFIG),d.value=n)}),[m,d,h,g,p,b,x,n]),w=useMemo(()=>Gesture.Race(y,v,I),[y,v,I]),C=useAnimatedStyle(()=>({transform:[{translateX:h.value},{translateY:g.value},{scale:m.value}]}),[h,g,m]);React.useEffect(()=>{l||S()},[l,S]);const _=e.alt??c(t+1,a);return _jsx(GestureDetector,{gesture:w,children:_jsx(Animated.View,{style:[lightboxImageStyles.container,{width:u.width}],children:_jsx(Animated.Image,{source:e.source,resizeMode:"contain",style:[lightboxImageStyles.image,C],accessibilityLabel:_,accessible:!0})})})},clamp=(e,t,a)=>Math.min(Math.max(e,t),a),buildStyles=e=>StyleSheet.create({container:{width:"100%"},carouselWrap:{width:"100%",position:"relative"},imageWrap:{width:"100%",aspectRatio:16/9,backgroundColor:e.colors["bg-subtle"],overflow:"hidden",borderRadius:e.radius.md,...smoothCorners},image:{width:"100%",height:"100%"},thumbnailImage:{width:"100%",height:"100%"},counterPill:{position:"absolute",top:12,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:"rgba(0,0,0,0.55)"}}),buildLightboxStyles=e=>StyleSheet.create({backdrop:{flex:1,backgroundColor:"#000",justifyContent:"center"},counterPill:{position:"absolute",top:48,alignSelf:"center",paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,...smoothCorners,backgroundColor:"rgba(0,0,0,0.6)"},closeButton:{position:"absolute",top:44,right:16,width:40,height:40,borderRadius:e.radius.pill,...smoothCorners,alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},captionWrap:{position:"absolute",left:0,right:0,bottom:32,paddingHorizontal:e.space.xl},captionText:{color:e.colors["on-scrim"],lineHeight:21}}),lightboxImageStyles=StyleSheet.create({container:{flex:1,alignItems:"center",justifyContent:"center"},image:{width:"100%",height:"100%"}});export{ImageGallery};export default ImageGallery;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{formatDate}from"@webority/mobile-core";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{FlatList,StyleSheet,View}from"react-native";import{KeyboardChatScrollView}from"react-native-keyboard-controller";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{smoothCorners}from"../../utils/corners.js";import{Badge}from"../Badge/index.js";import{DateSeparator,dayLabel}from"../DateSeparator/index.js";import{IconButton}from"../IconButton/index.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,
|
|
1
|
+
"use strict";import{formatDate}from"@webority/mobile-core";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{FlatList,StyleSheet,View}from"react-native";import{KeyboardChatScrollView}from"react-native-keyboard-controller";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{smoothCorners}from"../../utils/corners.js";import{Badge}from"../Badge/index.js";import{DateSeparator,dayLabel}from"../DateSeparator/index.js";import{IconButton}from"../IconButton/index.js";import{Spinner}from"../Spinner/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_MESSAGE_LIST_LABELS=Object.freeze({today:"Today",yesterday:"Yesterday",jumpToLatest:"Jump to the latest message",newMessages:e=>1===e?"1 new message":`${e} new messages`,unread:"New messages",loadingOlder:"Loading earlier messages"});const JUMP_AT=160,FOLLOW_AT=48,KEEP_POSITION={minIndexForVisible:0,autoscrollToTopThreshold:160},positionOf=(e,t)=>e?t?"middle":"last":t?"first":"single";export function MessageList({messages:e,keyExtractor:t,renderMessage:o,getAuthorKey:n,getDate:s,firstUnreadKey:r,onLoadOlder:a,loadingOlder:l=!1,hasOlder:i=!0,typing:u,empty:c,getAnnouncement:d,followNew:m,keyboardAware:p=!0,keyboardOffset:f,labels:y,now:g,onScroll:x,onContentSizeChange:b,contentContainerStyle:S,style:h,testID:j,...w}){const L=useTheme(),_=useSafeAreaInsets(),C=useReducedMotion(),E=useMemo(()=>buildStyles(L),[L]),v=useMemo(()=>({...DEFAULT_MESSAGE_LIST_LABELS,...y}),[y]),T=f??_.bottom,O=useRef(null),I=useRef(!1),k=useRef(!0),M=useRef(0),[A,D]=useState(!1),[V,P]=useState(0),R=useMemo(()=>{const o=s?e.map(e=>formatDate(s(e))):null,a=n?e.map(n):null,l=void 0===r?-1:e.findIndex(e=>t(e)===r);return e.map((t,n)=>{const r=n===e.length-1,i=null!==o&&(r||o[n]!==o[n+1]),u=null!==a&&!r&&a[n+1]===a[n]&&!i&&n!==l,c=null!==a&&n>0&&a[n-1]===a[n]&&(null===o||o[n-1]===o[n])&&n-1!==l;return{groupPosition:positionOf(u,c),day:i&&s?dayLabel(s(t),{now:g,labels:v}):null,unread:n===l}})},[e,s,n,r,t,g,v]),B=useCallback(()=>{k.current=!0,O.current?.scrollToOffset({offset:0,animated:!C}),P(0)},[C]),F=e.length>0?t(e[0]):null,z=useRef(F);useEffect(()=>{const o=z.current;if(z.current=F,null===o||null===F||o===F)return;const n=e.findIndex(e=>t(e)===o);if(-1===n)return void P(0);const s=e.slice(0,n).reverse();for(const e of s){const t=d?.(e);t&&announce(t)}m&&s.some(m)?B():I.current&&P(e=>e+s.length)},[F]);const K=useCallback(e=>{k.current=e.nativeEvent.contentOffset.y<=48;const t=e.nativeEvent.contentOffset.y>160;t!==I.current&&(I.current=t,D(t),t||P(0)),x?.(e)},[x]),N=useCallback((e,t)=>{const o=t>M.current;M.current=t,o&&k.current&&O.current?.scrollToOffset({offset:0,animated:!1}),b?.(e,t)},[b]),U=useCallback(()=>{i&&!l&&a?.()},[i,l,a]),$=useCallback(({item:e,index:t})=>{const n=R[t];return _jsxs(View,{children:[n?.day?_jsx(DateSeparator,{label:n.day}):null,n?.unread?_jsx(DateSeparator,{label:v.unread,emphasis:!0}):null,o({item:e,index:t,groupPosition:n?.groupPosition??"single"})]})},[R,v.unread,o]),G=useCallback(e=>t(e),[t]),H=useCallback(e=>_jsx(KeyboardChatScrollView,{...e,inverted:!0,offset:T}),[T]),J=V>0?`${v.newMessages(V)}. ${v.jumpToLatest}`:v.jumpToLatest;return _jsxs(View,{style:[E.root,h],children:[_jsx(FlatList,{keyboardShouldPersistTaps:"handled",maintainVisibleContentPosition:KEEP_POSITION,...w,ref:O,data:e,renderItem:$,keyExtractor:G,inverted:!0,onScroll:K,onContentSizeChange:N,onEndReached:a?U:void 0,ListHeaderComponent:u?_jsx(View,{children:u}):null,ListFooterComponent:l?_jsx(Spinner,{size:"sm",accessibilityLabel:v.loadingOlder,style:E.older}):null,ListEmptyComponent:c?_jsx(View,{style:E.fill,children:c}):null,renderScrollComponent:p?H:void 0,contentContainerStyle:[E.content,0===e.length?E.grow:null,S],testID:j}),A?_jsxs(View,{style:E.jump,pointerEvents:"box-none",children:[_jsx(View,{style:E.jumpDisc,children:_jsx(IconButton,{icon:"arrow-down",accessibilityLabel:J,variant:"ghost",tone:"neutral",onPress:B,testID:j?`${j}-jump`:void 0})}),V>0?_jsx(View,{style:E.count,pointerEvents:"none",importantForAccessibility:"no-hide-descendants",accessibilityElementsHidden:!0,children:_jsx(Badge,{value:V,max:99,tone:"primary",size:"sm"})}):null]}):null]})}const buildStyles=e=>StyleSheet.create({root:{flex:1},content:{paddingHorizontal:e.space.md,paddingVertical:e.space.sm},grow:{flexGrow:1},fill:{flex:1},older:{paddingVertical:e.space.md},jump:{position:"absolute",right:e.space.md,bottom:e.space.md},jumpDisc:{borderRadius:e.radius.pill,...smoothCorners,backgroundColor:e.colors.surface,...e.shadow.elevated},count:{position:"absolute",top:-e.space.xs,right:-e.space.xs}});export default MessageList;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState,useReducedMotion}from"../../hooks/index.js";import{createAnimatedValue,fontFor,resolveOtpInputSize,setNativeValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{FieldBase,FieldMessage,hasFieldText}from"../FieldBase/FieldBase.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_OTP_INPUT_LABELS=Object.freeze({field:e=>`Enter ${e}-digit code`});const sanitizeChar=(e,t)=>e?"number-pad"===t?e.replace(/\D/g,""):e:"",OTPInput=forwardRef((e,t)=>{const{value:n,defaultValue:i,onChange:s,onComplete:r,length:a=6,keyboardType:o="number-pad",autoFocus:l=!1,autoFocusDelay:u=0,disabled:c=!1,error:d,size:m="md",secure:p=!1,haptic:f,labels:g,onFocus:h,accessibilityLabel:b,style:y,cellStyle:x,textStyle:T,testID:v}=e;warnInvalidValue("OTPInput","size",e.size,["sm","md","lg"]),warnInvalidValue("OTPInput","keyboardType",e.keyboardType,["number-pad","default"]);const j=g?{...DEFAULT_OTP_INPUT_LABELS,...g}:DEFAULT_OTP_INPUT_LABELS,[I,
|
|
1
|
+
"use strict";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState,useReducedMotion}from"../../hooks/index.js";import{createAnimatedValue,fontFor,resolveOtpInputSize,setNativeValue,useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{FieldBase,FieldMessage,hasFieldText}from"../FieldBase/FieldBase.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_OTP_INPUT_LABELS=Object.freeze({field:e=>`Enter ${e}-digit code`});const sanitizeChar=(e,t)=>e?"number-pad"===t?e.replace(/\D/g,""):e:"",OTPInput=forwardRef((e,t)=>{const{value:n,defaultValue:i,onChange:s,onComplete:r,length:a=6,keyboardType:o="number-pad",autoFocus:l=!1,autoFocusDelay:u=0,disabled:c=!1,error:d,size:m="md",secure:p=!1,haptic:f,labels:g,onFocus:h,accessibilityLabel:b,style:y,cellStyle:x,textStyle:T,testID:v}=e;warnInvalidValue("OTPInput","size",e.size,["sm","md","lg"]),warnInvalidValue("OTPInput","keyboardType",e.keyboardType,["number-pad","default"]);const j=g?{...DEFAULT_OTP_INPUT_LABELS,...g}:DEFAULT_OTP_INPUT_LABELS,[I,C]=useControllableState({value:n,defaultValue:i??"",onChange:s}),E=useTheme(),V=useMemo(()=>buildStyles(E),[E]),w=resolveOtpInputSize(E,m),S=E.components["otp-input"][m].radius,A=useRef([]),[k,_]=useState(-1),[F,O]=useState(0),P=useRef(null),z=useRef(createAnimatedValue(0)).current,M=useRef(new Map),R=useMemo(()=>{const e=M.current,t=[];for(let n=0;n<a;n+=1){let i=e.get(n);i||(i=new Animated.Value(0),e.set(n,i)),t.push(i)}for(const t of Array.from(e.keys()))t>=a&&e.delete(t);return t},[a]),D=useRef(-1),L=E.settings.components["otp-input"]?.shakeOnError??!1,N=useReducedMotion(),B=!0===d||hasFieldText(d);useEffect(()=>{let e;return null===P.current||!B||P.current||(f&&triggerHaptic("notificationError"),L&&!N&&(setNativeValue(z,0),e=Animated.sequence([Animated.timing(z,{toValue:1,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0}),Animated.timing(z,{toValue:-1,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0}),Animated.timing(z,{toValue:1,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0}),Animated.timing(z,{toValue:0,duration:E.motion.duration.instant,easing:Easing.linear,useNativeDriver:!0})]),e.start())),P.current=B,()=>e?.stop()},[B,z,L,f,N,E.motion.duration.instant]),useEffect(()=>{const e=D.current;if(D.current=k,e===k)return;if(-1===e&&-1===k)return;const t=[];return R.forEach((n,i)=>{const s=i===k?1:0;if(i!==k&&i!==e)return;const r=Animated.timing(n,{toValue:s,duration:E.motion.duration.fast,easing:Easing.bezier(...E.motion.ease["in-out"]),useNativeDriver:!0});r.start(),t.push(r)}),()=>t.forEach(e=>{e.stop()})},[k,R,E]);const H=useCallback(e=>{const t=A.current[e];t&&t.focus()},[]);useImperativeHandle(t,()=>({focus:()=>H(0),blur:()=>{const e=A.current[k>=0?k:0];e?.blur()},clear:()=>{C(""),H(0)}}),[H,k,C]),useEffect(()=>{if(l&&!c){const e=setTimeout(()=>H(0),u);return()=>clearTimeout(e)}},[l,u,c,H]);const U=useMemo(()=>{const e=new Array(a).fill("");for(let t=0;t<Math.min(I.length,a);t+=1)e[t]=I[t]??"";return e},[I,a]),W=useCallback(e=>{const t=e.slice(0,a);t!==I&&(C(t),t.length===a&&r&&r(t))},[a,C,r,I]),$=useCallback((e,t)=>{const n=t.replace(/\u200B/g,""),i=sanitizeChar(n,o);if(!i){const t=U.slice(),n=(t[e]??"").length>0;if(t[e]="",W(t.join("").slice(0,a)),!n&&e>0){const t=U.slice();t[e-1]="",W(t.join("")),H(e-1)}return}const s=U[e]??"",r=s&&i.length>a&&i.startsWith(s)?i.slice(s.length):i;if(r.length>=a){const t=r.slice(0,a),n=I.length;return W(t),t.length!==n&&f&&triggerHaptic(f),void A.current[e]?.blur()}const l=U.slice();let u=e;for(let e=0;e<i.length&&u<a;e+=1)l[u]=i[e]??"",u+=1;const c=l.join("").slice(0,a),d=I.length;W(c),c.length!==d&&f&&triggerHaptic(f);const m=Math.min(u,a-1);u>=a?A.current[e]?.blur():H(m)},[U,H,o,a,f,W,I]),q=useCallback((e,t)=>{if("Backspace"!==t.nativeEvent.key)return;if(0===(U[e]??"").length){if(e>0){const t=U.slice();t[e-1]="",W(t.join("")),H(e-1)}}else{const t=U.slice();t[e]="",W(t.join(""))}},[U,H,W]),G=useCallback((e,t)=>{_(e),h?.(t)},[h]),K=useCallback(()=>{_(-1)},[]),X=useCallback(()=>{if(c)return;const e=U.indexOf("");H(-1===e?a-1:e)},[U,c,H,a]),J=useCallback(e=>{O(e.nativeEvent.layout.width)},[]),Q=b??j.field(a),Y=F>0?Math.max(24,Math.min(w.cell,Math.floor((F-w.gap*(a-1))/a))):w.cell,Z=z.interpolate({inputRange:[-1,1],outputRange:[-6,6]});return _jsxs(View,{style:y,onLayout:J,accessible:!0,accessibilityRole:"none",accessibilityLabel:Q,accessibilityValue:{text:n},accessibilityState:{disabled:c},"aria-disabled":c,testID:v,children:[_jsx(Pressable,{onPress:X,disabled:c,accessible:!1,children:_jsx(Animated.View,{style:[V.row,{columnGap:w.gap,transform:[{translateX:Z}]}],children:U.map((e,t)=>{const n=k===t,i=e.length>0,s=B?E.colors["danger-border"]:E.colors["focus-ring"],r=R[t];if(!r)return null;const l=p&&i?"●":e;return _jsxs(View,{style:V.cellWrapper,children:[_jsxs(FieldBase,{size:m,width:Y,height:Y,radius:S,borderWidth:1.5,focused:n,error:B,filled:i,disabled:c,paddingHorizontal:E.space.none,paddingVertical:E.space.none,gap:E.space.none,style:x,children:[_jsx(TextInput,{ref:e=>{A.current[t]=e},value:(p&&i?"":e)||"",onChangeText:e=>$(t,e),onKeyPress:e=>q(t,e),onFocus:e=>G(t,e),onBlur:K,keyboardType:o,editable:!c,selectTextOnFocus:!0,caretHidden:i,maxLength:a+1,textContentType:"oneTimeCode",autoComplete:0===t?"sms-otp":"off",importantForAutofill:0===t?"yes":"no",style:[V.input,{fontSize:w.text,color:E.colors["text-body"],...fontFor(E,"semibold")},T]}),p&&i?_jsx(View,{pointerEvents:"none",style:V.maskOverlay,children:_jsx(Text,{variant:"body",weight:"semibold",style:[{fontSize:w.text},T],children:l})}):null]}),_jsx(Animated.View,{style:[V.underline,{backgroundColor:s,opacity:r}]})]},`otp-cell-${t}`)})})}),_jsx(FieldMessage,{size:m,error:!0,text:d})]})});OTPInput.displayName="OTPInput";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},cellWrapper:{alignItems:"center"},input:{width:"100%",height:"100%",textAlign:"center",padding:e.space.none},maskOverlay:{...StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center"},underline:{marginTop:e.space.xs,height:2,width:"60%",borderRadius:e.radius.pill,...smoothCorners}});export{OTPInput};export default OTPInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,StyleSheet,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{AppIcon}from"../AppIcon/index.js";import{Button}from"../Button/index.js";import{EmptyState}from"../EmptyState/index.js";import{IconButton}from"../IconButton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const MIN_FRAME=240,DEFAULT_FRAME=260,MARK_LENGTH=32,MARK_THICKNESS=4,LIFT=.06,BREATHE_SCALE=1.03,SNAP_SCALE=1.08,T=4,CORNERS=[{key:"tl",style:{top:0,left:0,borderTopWidth:4,borderLeftWidth:4}},{key:"tr",style:{top:0,right:0,borderTopWidth:4,borderRightWidth:4}},{key:"bl",style:{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4}},{key:"br",style:{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4}}];export const DEFAULT_SCANNER_OVERLAY_LABELS=Object.freeze({hint:"Point the camera at the code",found:"Code found",invalid:"This code cannot be used. Try another.",torchOn:"Turn torch on",torchOff:"Turn torch off",manualEntry:"Enter code instead",gallery:"Upload from gallery",noPermissionTitle:"Camera access is off",noPermissionMessage:"Allow camera access to scan a code.",permissionAction:"Allow camera access",noCameraTitle:"No camera found",noCameraMessage:"This device has no camera available. You can still add the code another way."});const ScannerOverlay=forwardRef((e,t)=>{warnInvalidValue("ScannerOverlay","state",e.state,["scanning","found","invalid","noPermission","noCamera"]);const{children:o,state:n="scanning",helperText:i,labels:s,torch:a=!1,onTorchChange:r,onManualEntry:l,onGallery:c,onPermissionAction:d,frameSize:m=DEFAULT_FRAME,haptic:u,style:h,testID:f}=e,p=useTheme(),g=useSafeAreaInsets(),y=useReducedMotion(),
|
|
1
|
+
"use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,StyleSheet,View}from"react-native";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{smoothCorners}from"../../utils/corners.js";import{triggerHaptic}from"../../utils/hapticUtils.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{AppIcon}from"../AppIcon/index.js";import{Button}from"../Button/index.js";import{EmptyState}from"../EmptyState/index.js";import{IconButton}from"../IconButton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";const MIN_FRAME=240,DEFAULT_FRAME=260,MARK_LENGTH=32,MARK_THICKNESS=4,LIFT=.06,BREATHE_SCALE=1.03,SNAP_SCALE=1.08,T=4,CORNERS=[{key:"tl",style:{top:0,left:0,borderTopWidth:4,borderLeftWidth:4}},{key:"tr",style:{top:0,right:0,borderTopWidth:4,borderRightWidth:4}},{key:"bl",style:{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4}},{key:"br",style:{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4}}];export const DEFAULT_SCANNER_OVERLAY_LABELS=Object.freeze({hint:"Point the camera at the code",found:"Code found",invalid:"This code cannot be used. Try another.",torchOn:"Turn torch on",torchOff:"Turn torch off",manualEntry:"Enter code instead",gallery:"Upload from gallery",noPermissionTitle:"Camera access is off",noPermissionMessage:"Allow camera access to scan a code.",permissionAction:"Allow camera access",noCameraTitle:"No camera found",noCameraMessage:"This device has no camera available. You can still add the code another way."});const ScannerOverlay=forwardRef((e,t)=>{warnInvalidValue("ScannerOverlay","state",e.state,["scanning","found","invalid","noPermission","noCamera"]);const{children:o,state:n="scanning",helperText:i,labels:s,torch:a=!1,onTorchChange:r,onManualEntry:l,onGallery:c,onPermissionAction:d,frameSize:m=DEFAULT_FRAME,haptic:u,style:h,testID:f}=e,p=useTheme(),g=useSafeAreaInsets(),y=useReducedMotion(),x=useMemo(()=>buildStyles(p),[p]),b=useMemo(()=>({...DEFAULT_SCANNER_OVERLAY_LABELS,...s}),[s]),j=i??b.hint,[v,S]=useState({width:0,height:0}),w="scanning"===n||"found"===n||"invalid"===n,A=useRef(createAnimatedValue(1)).current,_=p.motion.duration.slower,E=p.motion.duration.default;useEffect(()=>{if(A.setValue(1),y)return;let e;return"scanning"===n&&_>0?e=Animated.loop(Animated.sequence([Animated.timing(A,{toValue:1.03,duration:2*_,useNativeDriver:!0}),Animated.timing(A,{toValue:1,duration:2*_,useNativeDriver:!0})])):"found"===n&&E>0&&(A.setValue(1.08),e=Animated.timing(A,{toValue:1,duration:E,useNativeDriver:!0})),e?.start(),()=>e?.stop()},[n,y,_,E,A]);const V=useRef(n);useEffect(()=>{V.current!==n&&(V.current=n,!1!==u&&("found"===n?triggerHaptic("notificationSuccess"):"invalid"===n&&triggerHaptic("notificationError")))},[n,u]);const{found:C,invalid:R}=b,{noPermissionTitle:I,noPermissionMessage:M}=b,{noCameraTitle:L,noCameraMessage:P}=b;useEffect(()=>{switch(n){case"scanning":announce(j);break;case"found":announce(C);break;case"invalid":announce(R,{polite:!1});break;case"noPermission":announce(`${I}. ${M}`);break;case"noCamera":announce(`${L}. ${P}`)}},[n,j,C,R,I,M,L,P]);const k=Math.max(240,Math.min(m,v.width-2*p.space.xl)),F=(v.width-k)/2,N=Math.max(p.space.md,(v.height-k)/2-.06*v.height),O=v.width>0&&v.height>0,B={borderColor:"found"===n?p.colors.success:"invalid"===n?p.colors.danger:p.colors["on-scrim"],width:32,height:32},D="found"===n||"invalid"===n?_jsx(View,{style:[x.pill,{backgroundColor:"found"===n?p.colors.success:p.colors.danger}],children:_jsx(Text,{variant:"bodySmall",weight:"semibold",align:"center",style:{color:"found"===n?p.colors["on-success"]:p.colors["on-danger"]},children:"found"===n?C:R})}):_jsx(Text,{variant:"bodySmall",align:"center",style:{color:p.colors["on-scrim"]},children:j}),H=w&&null!=r,z=w?"glass":"outline";return _jsxs(View,{ref:t,testID:f,onLayout:e=>{const{width:t,height:o}=e.nativeEvent.layout;S(e=>e.width===t&&e.height===o?e:{width:t,height:o})},style:[x.root,!w&&{backgroundColor:p.colors.bg},h],children:[w?_jsx(View,{style:StyleSheet.absoluteFill,children:o}):null,w&&O?_jsx(_Fragment,{children:_jsxs(View,{pointerEvents:"none",style:StyleSheet.absoluteFill,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:[_jsx(View,{style:[x.scrim,{left:0,right:0,top:0,height:N}]}),_jsx(View,{style:[x.scrim,{left:0,right:0,top:N+k,bottom:0}]}),_jsx(View,{style:[x.scrim,{left:0,width:F,top:N,height:k}]}),_jsx(View,{style:[x.scrim,{left:F+k,right:0,top:N,height:k}]}),_jsx(Animated.View,{style:{position:"absolute",left:F,top:N,width:k,height:k,transform:[{scale:A}]},children:CORNERS.map(e=>_jsx(View,{style:[x.mark,B,e.style]},e.key))})]})}):null,w?null:_jsx(View,{style:x.panel,children:_jsx(EmptyState,{fill:!0,icon:_jsx(AppIcon,{name:"noPermission"===n?"camera":"camera-slash",size:48,color:p.colors["text-subtle"]}),title:"noPermission"===n?I:L,description:"noPermission"===n?M:P,action:"noPermission"===n&&d?{label:b.permissionAction,onPress:d}:void 0})}),_jsxs(View,{pointerEvents:"box-none",style:[x.bar,{paddingBottom:Math.max(g.bottom,p.space.md)}],children:[w&&O?_jsx(View,{pointerEvents:"none",style:x.message,children:D}):null,_jsxs(View,{style:x.actions,children:[H?_jsx(IconButton,{icon:a?"flash":"flash-slash",variant:"glass",size:"lg",active:a,haptic:u,accessibilityLabel:a?b.torchOff:b.torchOn,onPress:()=>r?.(!a)}):null,c?_jsx(Button,{label:b.gallery,leftIcon:"gallery",variant:z,tone:"neutral",size:"lg",haptic:u,onPress:c}):null,l?_jsx(Button,{label:b.manualEntry,leftIcon:"keyboard",variant:z,tone:"neutral",size:"lg",haptic:u,onPress:l}):null]})]})]})});ScannerOverlay.displayName="ScannerOverlay";const buildStyles=e=>StyleSheet.create({root:{flex:1,overflow:"hidden"},scrim:{position:"absolute",backgroundColor:e.colors.scrim},mark:{position:"absolute"},message:{alignItems:"center",paddingHorizontal:e.space.xl},pill:{paddingHorizontal:e.space.md,paddingVertical:e.space.xs,borderRadius:e.radius.pill,...smoothCorners},panel:{...StyleSheet.absoluteFill,justifyContent:"center"},bar:{position:"absolute",left:0,right:0,bottom:0,flexDirection:"column",alignItems:"center",justifyContent:"center",gap:e.space.sm,paddingHorizontal:e.space.md},actions:{flexDirection:"row",flexWrap:"wrap",alignItems:"center",justifyContent:"center",gap:e.space.sm}});export{ScannerOverlay};export default ScannerOverlay;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{cloneElement,createElement,isValidElement,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,BackHandler,FlatList,StyleSheet,View}from"react-native";import{KeyboardStickyView}from"react-native-keyboard-controller";import{useSharedValue}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useRefreshControl}from"../../hooks/useRefreshControl.js";import{resolveFloatingActionButtonSize,useTheme}from"../../theme/index.js";import{AppBar}from"../AppBar/index.js";import{AsyncBlock}from"../AsyncBlock/index.js";import{EmptyState}from"../EmptyState/index.js";import{KeyboardAwareScrollView}from"../KeyboardAwareScrollView/index.js";import{KeyboardToolbar}from"../KeyboardToolbar/index.js";import{PagedListFooter}from"../PagedListFooter/index.js";import{ScrollHostContext}from"./ScrollHost.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";const DEFAULT_EDGES=["top","bottom"],SCROLL_EVENT_THROTTLE=16,noop=()=>{};function renderFooter(e){return isValidElement(e)?e:e?createElement(e):null}const topPaddingOf=e=>{const t=StyleSheet.flatten(e),o=t?.paddingTop??t?.paddingVertical??t?.padding;return"number"==typeof o?o:0},buildStyles=e=>StyleSheet.create({flex:{flex:1},root:{flex:1,backgroundColor:e.colors.bg},overlay:{position:"absolute",top:0,left:0,right:0},footer:{backgroundColor:e.colors.bg,borderTopWidth:StyleSheet.hairlineWidth,borderTopColor:e.colors.border}});export function Screen(e){const{title:t,subtitle:o,largeTitle:
|
|
1
|
+
"use strict";import{cloneElement,createElement,isValidElement,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,BackHandler,FlatList,StyleSheet,View}from"react-native";import{KeyboardStickyView}from"react-native-keyboard-controller";import{useSharedValue}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useRefreshControl}from"../../hooks/useRefreshControl.js";import{resolveFloatingActionButtonSize,useTheme}from"../../theme/index.js";import{AppBar}from"../AppBar/index.js";import{AsyncBlock}from"../AsyncBlock/index.js";import{EmptyState}from"../EmptyState/index.js";import{KeyboardAwareScrollView}from"../KeyboardAwareScrollView/index.js";import{KeyboardToolbar}from"../KeyboardToolbar/index.js";import{PagedListFooter}from"../PagedListFooter/index.js";import{ScrollHostContext}from"./ScrollHost.js";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";const DEFAULT_EDGES=["top","bottom"],SCROLL_EVENT_THROTTLE=16,noop=()=>{};function renderFooter(e){return isValidElement(e)?e:e?createElement(e):null}const topPaddingOf=e=>{const t=StyleSheet.flatten(e),o=t?.paddingTop??t?.paddingVertical??t?.padding;return"number"==typeof o?o:0},buildStyles=e=>StyleSheet.create({flex:{flex:1},root:{flex:1,backgroundColor:e.colors.bg},overlay:{position:"absolute",top:0,left:0,right:0},headerRaised:{zIndex:1},footer:{backgroundColor:e.colors.bg,borderTopWidth:StyleSheet.hairlineWidth,borderTopColor:e.colors.border}});export function Screen(e){const{title:t,subtitle:o,largeTitle:n=!0,headerShadowOnScroll:r,onBack:l,rightActions:a,leading:s,trailing:i,children:d,onRefresh:c,refreshing:u=!1,footer:f,scroll:m=!0,list:p,edges:h=DEFAULT_EDGES,keyboardToolbar:g=!0,bottomInset:y=0,gutter:S,floatingAction:v,scrollRef:b,onScroll:x,contentContainerStyle:E,testID:C}=e,T=useTheme(),j=S??void 0===p,R=T.space[T.components.screen.gutter],k=j?R:0,L=useSafeAreaInsets(),_=useMemo(()=>buildStyles(T),[T]),[A]=useState(()=>new Animated.Value(0)),[V,w]=useState(0),[F,B]=useState(0),O=void 0!==l,M=useRef(l);M.current=l;const P=Boolean(t||o||l||s||i||a?.length),z=n&&void 0!==t,H=z&&(void 0!==p||m),K=H?V:0,D=P&&!H&&(r??T.settings.components.screen?.headerShadowOnScroll??!0),[I,N]=useState(!1),W=useRef(D);W.current=D;const headerGap=e=>e>0?e:P?T.space.lg:0,G=void 0!==f,{refreshControl:U}=useRefreshControl({onRefresh:c??noop,refreshing:u}),Y=c?cloneElement(U,{progressViewOffset:K}):void 0,q=useSharedValue(0),J=useSharedValue(0),Q=useSharedValue(0),X=useSharedValue(0),Z=useRef(null),$=useRef(0),ee=useRef(0),te=useMemo(()=>({top:q,bottom:J,offset:Q,maxOffset:X,scrollTo:e=>{const t=Z.current;t instanceof FlatList?t.scrollToOffset({offset:e,animated:!1}):t?.scrollTo({y:e,animated:!1})}}),[q,J,Q,X]),oe=useCallback(e=>{Z.current=e,"function"==typeof b?b(e):b&&(b.current=e)},[b]),ne=useCallback(()=>{X.value=Math.max(0,$.current-ee.current)},[X]),re=useRef(x);re.current=x;const le=useMemo(()=>Animated.event([{nativeEvent:{contentOffset:{y:A}}}],{useNativeDriver:!1,listener:e=>{if(Q.value=e.nativeEvent.contentOffset.y,W.current){const t=e.nativeEvent.contentOffset.y>0;N(e=>e===t?e:t)}re.current?.(e)}}),[A,Q]),ae=useCallback(e=>{const{height:t}=e.nativeEvent.layout;w(e=>Math.max(e,t))},[]),se=useCallback(e=>{B(e.nativeEvent.layout.height)},[]);useEffect(()=>{if(!O)return;const e=BackHandler.addEventListener("hardwareBackPress",()=>(M.current?.(),!0));return()=>e.remove()},[O]);const ie=h.includes("left")?L.left:0,de=h.includes("right")?L.right:0,ce=h.includes("bottom")?L.bottom:0,ue=h.includes("top")&&!P?L.top:0,fe=T.space[T.components["floating-action-button"]["bottom-offset"]],me=v?.props.bottomOffset??fe,pe=v?resolveFloatingActionButtonSize(T,v.props.size??"md").diameter+me+T.space.lg:0,he=G?Math.max(0,F-L.bottom):y,ge=v?cloneElement(v,{bottomOffset:me+he,position:v.props.position??"bottomRight"}):null,ye=G?pe:Math.max(ce,v?pe+L.bottom:0),Se=y+ye-(G?0:ce),ve=h.filter(e=>"top"!==e&&!("bottom"===e&&G)),be=P?_jsx(View,{style:H?_.overlay:D?_.headerRaised:void 0,onLayout:H?ae:void 0,children:_jsx(AppBar,{title:t,subtitle:o,variant:z?"large":"default",scrollY:H?A:void 0,elevated:D&&I,onBack:l,rightActions:a,leading:s,trailing:i,gutter:R})}):null,xe=useCallback(()=>{const e=Z.current?.getNativeScrollRef();e&&e.measureInWindow((e,t,o,n)=>{ee.current=n,q.value=t+K,J.value=t+n,ne()})},[K,q,J,ne]);useEffect(()=>{xe()},[xe]);const Ee=useCallback((e,t)=>{$.current=t,ne()},[ne]);let Ce;if(void 0!==p){const{state:e,paging:t,...o}=p,n=topPaddingOf([o.contentContainerStyle,E]),handleEndReached=e=>{t?.hasMore&&!t.loadingMore&&null==t.errorMore&&t.loadMore(),o.onEndReached?.(e)},r=_jsx(FlatList,{keyboardShouldPersistTaps:"handled",onEndReachedThreshold:t?.5:void 0,...o,ref:oe,refreshControl:Y,onScroll:le,onLayout:e=>{xe(),o.onLayout?.(e)},onContentSizeChange:(e,t)=>{Ee(e,t),o.onContentSizeChange?.(e,t)},onEndReached:t?handleEndReached:o.onEndReached,ListEmptyComponent:e?.empty?_jsx(EmptyState,{...e.empty}):void 0,ListFooterComponent:t||o.ListFooterComponent?_jsxs(_Fragment,{children:[renderFooter(o.ListFooterComponent),t?_jsx(PagedListFooter,{paging:t}):null]}):void 0,scrollEventThrottle:16,style:_.flex,contentContainerStyle:[{paddingTop:K,paddingLeft:ie+k,paddingRight:de+k},{paddingBottom:y+ye},o.contentContainerStyle,E,{paddingTop:K+headerGap(n)}]});Ce=_jsx(ScrollHostContext.Provider,{value:te,children:e?_jsx(AsyncBlock,{loading:e.loading,error:e.error,errorTitle:e.errorTitle,onRetry:e.onRetry,skeleton:e.skeleton,style:[_.flex,{paddingTop:K+headerGap(n)}],children:r}):r})}else Ce=m?_jsx(ScrollHostContext.Provider,{value:te,children:_jsxs(KeyboardAwareScrollView,{ref:oe,refreshControl:Y,onScroll:le,scrollEventThrottle:16,onLayout:xe,onContentSizeChange:Ee,safeAreaEdges:ve,style:_.flex,contentContainerStyle:[{paddingHorizontal:k},E,{paddingTop:K+headerGap(topPaddingOf(E))}],children:[d,Se>0?_jsx(View,{style:{height:Se}}):null]})}):_jsx(View,{style:[_.flex,{paddingLeft:ie+k,paddingRight:de+k,paddingBottom:y+ye},E],children:d});const Te=G?_jsx(KeyboardStickyView,{onLayout:se,style:[_.footer,{paddingLeft:ie+R,paddingRight:de+R,paddingBottom:ce+y}],children:f}):null;return _jsxs(View,{testID:C,style:[_.root,{paddingTop:ue}],children:[H?null:be,Ce,Te,ge,void 0!==p?d:null,H?be:null,g?_jsx(KeyboardToolbar,{}):null]})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,resolveSegmentedControlSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{FieldLabel,FieldMessage,hasFieldText}from"../FieldBase/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const LABEL_LINE_HEIGHT_RATIO=1.25,activeInkFor=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"neutral":return e.colors["text-body"];case"success":return e.colors["success-text"];case"warning":return e.colors["warning-text"];case"danger":return e.colors["danger-text"];default:return e.colors["info-text"]}},SegmentedControl=forwardRef((e,t)=>{const{segments:r,label:i,helperText:s,error:l,value:n,defaultValue:o,onChange:a,size:d="md",fullWidth:c=!0,disabled:u=!1,tone:m="primary",variant:
|
|
1
|
+
"use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,resolveSegmentedControlSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{FieldLabel,FieldMessage,hasFieldText}from"../FieldBase/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const LABEL_LINE_HEIGHT_RATIO=1.25,activeInkFor=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"neutral":return e.colors["text-body"];case"success":return e.colors["success-text"];case"warning":return e.colors["warning-text"];case"danger":return e.colors["danger-text"];default:return e.colors["info-text"]}},SegmentedControl=forwardRef((e,t)=>{const{segments:r,label:i,helperText:s,error:l,value:n,defaultValue:o,onChange:a,size:d="md",fullWidth:c=!0,disabled:u=!1,tone:m="primary",variant:h="segmented",radius:g,labelLines:p=1,haptic:f,accessibilityLabel:x,style:b,containerStyle:S,segmentStyle:y,selectedIndicatorStyle:v,textStyle:w,labelStyle:C,testID:j}=e;warnInvalidValue("SegmentedControl","size",e.size,["sm","md","lg"]),warnInvalidValue("SegmentedControl","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("SegmentedControl","variant",e.variant,["underline","pills","segmented"]);const[I,V]=useControllableState({value:n,defaultValue:o??r[0]?.value,onChange:a}),k=useTheme(),F=k.components["segmented-control"],L=useMemo(()=>buildStyles(k),[k]),_=useMemo(()=>resolveSegmentedControlSize(k,d),[k,d]),z=p>=2?2:1,M=z>1,R="segmented"===h,T="underline"===h,A="pills"===h,E=R?k.space[F["track-padding"]]:0,H=Math.ceil(1.25*_.text)*(z-1),q=F["underline-height"],D=k.space[F["pill-inset"]],B="number"==typeof g?g:g?k.radius[g]:void 0,W=B??k.radius.md,P=void 0===B?k.radius.sm:Math.max(B-E,0),N=B??k.radius.pill,G=B??k.radius.none,[O,X]=useState([]),J=useRef(createAnimatedValue(0)).current,K=Math.max(0,r.findIndex(e=>e.value===I)),Q=O[K],U=Q?.x,Y=useCallback(e=>{const t=k.motion.spring.snappy,r=Animated.spring(J,{toValue:e,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!0});return r.start(),r},[k.motion.spring.snappy,J]);useEffect(()=>{X(e=>e.length===r.length||0===e.length?e:[])},[r.length]);const Z=useRef(null);useEffect(()=>{if(void 0===U)return;const e=null!==Z.current&&Z.current!==K;if(Z.current=K,!e)return void J.setValue(U);const t=Y(U);return()=>t.stop()},[K,U,Y,J]);const $=useCallback((e,t)=>{const{x:r,width:i}=t.nativeEvent.layout;X(t=>{const s=t[e];if(s&&s.x===r&&s.width===i)return t;const l=t.slice();return l[e]={x:r,width:i},l})},[]),ee=useCallback(e=>{if(u)return;if(e.value===I)return;const t=resolveHaptic(f,"selection");t&&triggerHaptic(t),V(e.value)},[u,V,I,f]),te=R?k.colors.surface:A?k.colors["primary-soft"]:k.colors.primary,re=R?P:A?N:G,ie=activeInkFor(k,m),se=k.colors["bg-muted"],le=useSquircle(R,W),ne=!0===l||hasFieldText(l),oe=ne&&!u,ae=k.colors["field-border-error"],de=k.size.border,ce=hasFieldText(i),ue=ne?l:s,me=hasFieldText(ue),he=_jsxs(View,{ref:t,accessibilityRole:"radiogroup",accessibilityLabel:x??("string"==typeof i?i:void 0),testID:j,style:[L.track,{...M?{minHeight:_.height+H}:{height:_.height},opacity:u?.55:1,alignSelf:c?"stretch":"flex-start"},R?{borderRadius:W,...smoothCorners,backgroundColor:le.active?"transparent":se,padding:E}:T?{borderBottomColor:oe?ae:k.colors["border-subtle"],borderBottomWidth:StyleSheet.hairlineWidth}:null,S,b],onLayout:le.onLayout,children:[le.active&&le.size?_jsx(SquircleFill,{width:le.size.width,height:le.size.height,radius:W,fill:se,stroke:oe?ae:void 0,strokeWidth:de}):null,_jsxs(View,{style:L.row,children:[Q?_jsx(Animated.View,{pointerEvents:"none",style:[L.thumb,R?M?{top:0,bottom:0}:{top:0,height:_.height-2*E}:A?{top:D,bottom:D,left:D}:{bottom:0,height:q},{width:A?Math.max(Q.width-2*D,0):Q.width,borderRadius:re,...smoothCorners,backgroundColor:te,transform:[{translateX:J}]},v]}):null,r.map((e,t)=>{const r=e.value===I,i=r?ie:k.colors["text-subtle"],s=renderSlotIcon(e.icon,{color:i,size:_.icon,selected:r,disabled:u});return _jsxs(Pressable,{onPress:()=>ee(e),onLayout:e=>$(t,e),disabled:u,accessibilityRole:"radio",accessibilityLabel:e.label,accessibilityState:{checked:r,selected:r,disabled:u},"aria-checked":r,"aria-disabled":u,style:({pressed:e})=>[L.segment,M?L.segmentMultiline:null,{paddingHorizontal:_["padding-x"],opacity:e&&!r?.7:1},y],children:[s?_jsx(View,{style:L.segmentIcon,children:s}):null,_jsx(Text,{variant:"label",weight:r?"semibold":"medium",style:[L.segmentLabel,M?L.segmentLabelMultiline:null,{color:i,fontSize:_.text},w,C],numberOfLines:z,children:e.label})]},String(e.value))})]}),!oe||T||le.active?null:_jsx(View,{pointerEvents:"none",style:[StyleSheet.absoluteFill,{borderWidth:de,borderColor:ae,borderRadius:R?W:N,...smoothCorners}]})]});return ce||me?_jsxs(View,{style:{alignSelf:c?"stretch":"flex-start"},children:[ce?_jsx(FieldLabel,{size:d,children:i}):null,he,me?_jsx(FieldMessage,{size:d,text:ue,error:ne}):null]}):he});SegmentedControl.displayName="SegmentedControl";const buildStyles=e=>StyleSheet.create({track:{flexDirection:"row",alignItems:"stretch",position:"relative"},row:{flex:1,flexDirection:"row",alignItems:"stretch",position:"relative",overflow:"hidden"},thumb:{position:"absolute",left:0},segment:{flexGrow:1,flexShrink:1,flexBasis:"auto",flexDirection:"row",alignItems:"center",justifyContent:"center"},segmentIcon:{marginRight:e.space.xs},segmentMultiline:{paddingVertical:e.space.xs},segmentLabel:{includeFontPadding:!1},segmentLabelMultiline:{flexShrink:1,textAlign:"center"}});export{SegmentedControl};export default SegmentedControl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import React,{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{cancelAnimation,Easing,runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SLIDE_TO_CONFIRM_LABELS=Object.freeze({slide:"Slide to confirm",confirmed:"Confirmed",confirmAction:"Confirm"});const SIZE_MAP={sm:{height:44,pad:"xxs"},md:{height:56,pad:"xs"},lg:{height:64,pad:"sm"}},Chevron=({color:e,size:t})=>_jsx(View,{style:{width:0,height:0,borderTopWidth:.4*t,borderBottomWidth:.4*t,borderLeftWidth:.55*t,borderTopColor:"transparent",borderBottomColor:"transparent",borderLeftColor:e,marginLeft:.2*t}}),SlideToConfirm=forwardRef((e,t)=>{const{onConfirm:i,label:a,tone:r="primary",size:o="md",disabled:n=!1,threshold:s=.9,resetAfter:l=!1,haptic:c,icon:d,labels:u,style:m,trackStyle:h,handleStyle:f,labelStyle:p,testID:b}=e;warnInvalidValue("SlideToConfirm","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("SlideToConfirm","size",e.size,["sm","md","lg"]);const g=useMemo(()=>({...DEFAULT_SLIDE_TO_CONFIRM_LABELS,...u}),[u]),S=useMemo(()=>[{name:"activate",label:g.confirmAction},{name:"increment",label:g.confirmAction}],[g.confirmAction]),v=useTheme(),y=SIZE_MAP[o],C=v.space[y.pad],x=y.height-2*C,w=useMemo(()=>buildStyles(v,y),[v,y]),A=v.colors[r],[T,j]=useState(!1),_=useSharedValue(0),E=useSharedValue(0),k=useSharedValue(0),L=useRef(null),V=useCallback(()=>{const e=resolveHaptic(c,"notificationSuccess");e&&triggerHaptic(e)},[c]),I=useCallback(()=>{j(!1),_.value=withSpring(0,{damping:18,stiffness:160,mass:1})},[_]),M=useCallback(()=>{j(!0),V(),i(),!1!==l&&(L.current&&clearTimeout(L.current),L.current=setTimeout(I,l))},[V,i,l,I]),R=useCallback(e=>{if(n||T)return;const{actionName:t}=e.nativeEvent;"activate"!==t&&"increment"!==t||M()},[n,T,M]);React.useEffect(()=>()=>{cancelAnimation(_),L.current&&clearTimeout(L.current)},[_]);const D=useCallback(e=>{E.value=Math.max(0,e.nativeEvent.layout.width-x-2*C)},[E,x,C]),O=useMemo(()=>{const e=s,t={damping:18,stiffness:160,mass:1},i={duration:v.motion.duration.fast,easing:Easing.out(Easing.cubic)};return Gesture.Pan().enabled(!n&&!T).minDistance(0).onStart(()=>{"worklet";k.value=_.value}).onUpdate(e=>{"worklet";_.value=Math.min(Math.max(k.value+e.translationX,0),E.value)}).onEnd(()=>{"worklet";E.value>0&&_.value>=E.value*e?(_.value=withTiming(E.value,i),runOnJS(M)()):_.value=withSpring(0,t)})},[n,T,s,_,E,k,M,v.motion.duration.fast]),z=useAnimatedStyle(()=>({transform:[{translateX:_.value}]})),F=useAnimatedStyle(()=>({width:_.value+x+C})),W=useAnimatedStyle(()=>{const e=E.value>0?E.value:1;return{opacity:Math.max(0,1-_.value/(.6*e))}});return _jsxs(View,{ref:t,style:[w.track,{backgroundColor:v.colors["bg-subtle"]},h,m],onLayout:D,testID:b,accessibilityRole:"adjustable",accessibilityLabel:T?g.confirmed:a??g.slide,accessibilityState:{disabled:n},"aria-disabled":n,accessibilityActions:S,onAccessibilityAction:R,children:[_jsx(Animated.View,{style:[w.fill,{backgroundColor:A,opacity:n?.5:1},F],pointerEvents:"none"}),_jsx(Animated.View,{style:[w.labelWrap,W],pointerEvents:"none",children:_jsx(Text,{variant:"body",style:[w.label,{color:v.colors["text-muted"]},p],numberOfLines:1,children:T?g.confirmed:a??g.slide})}),_jsx(GestureDetector,{gesture:O,children:_jsx(Animated.View,{style:[w.handle,{width:x,height:x,borderRadius:v.radius.pill,...smoothCorners,backgroundColor:v.colors.surface,opacity:n?.5:1,...v.shadow.card},f,z],children:d??_jsx(Chevron,{color:A,size:.5*x})})})]})});SlideToConfirm.displayName="SlideToConfirm";const buildStyles=(e,t)=>StyleSheet.create({track:{height:t.height,borderRadius:e.radius.pill,...smoothCorners,justifyContent:"center",overflow:"hidden",padding:e.space[t.pad]},fill:{position:"absolute",left:0,top:0,bottom:0,borderRadius:e.radius.pill,...smoothCorners},labelWrap:{position:"absolute",left:t.height,right:t.height},label:{textAlign:"center",includeFontPadding:!1},handle:{alignItems:"center",justifyContent:"center"}});export{SlideToConfirm};export default SlideToConfirm;
|
|
1
|
+
"use strict";import React,{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{cancelAnimation,Easing,runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SLIDE_TO_CONFIRM_LABELS=Object.freeze({slide:"Slide to confirm",confirmed:"Confirmed",confirmAction:"Confirm"});const SIZE_MAP={sm:{height:44,pad:"xxs"},md:{height:56,pad:"xs"},lg:{height:64,pad:"sm"}},Chevron=({color:e,size:t})=>_jsx(View,{style:{width:0,height:0,borderTopWidth:.4*t,borderBottomWidth:.4*t,borderLeftWidth:.55*t,borderTopColor:"transparent",borderBottomColor:"transparent",borderLeftColor:e,marginLeft:.2*t}}),SlideToConfirm=forwardRef((e,t)=>{const{onConfirm:i,label:a,tone:r="primary",size:o="md",disabled:n=!1,threshold:s=.9,resetAfter:l=!1,haptic:c,icon:d,labels:u,style:m,trackStyle:h,handleStyle:f,labelStyle:p,testID:b}=e;warnInvalidValue("SlideToConfirm","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("SlideToConfirm","size",e.size,["sm","md","lg"]);const g=useMemo(()=>({...DEFAULT_SLIDE_TO_CONFIRM_LABELS,...u}),[u]),S=useMemo(()=>[{name:"activate",label:g.confirmAction},{name:"increment",label:g.confirmAction}],[g.confirmAction]),v=useTheme(),y=SIZE_MAP[o],C=v.space[y.pad],x=y.height-2*C,w=useMemo(()=>buildStyles(v,y),[v,y]),A=v.colors[r],[T,j]=useState(!1),_=useSharedValue(0),E=useSharedValue(0),k=useSharedValue(0),L=useRef(null),V=useCallback(()=>{const e=resolveHaptic(c,"notificationSuccess");e&&triggerHaptic(e)},[c]),I=useCallback(()=>{j(!1),_.value=withSpring(0,{damping:18,stiffness:160,mass:1})},[_]),M=useCallback(()=>{j(!0),V(),i(),!1!==l&&(L.current&&clearTimeout(L.current),L.current=setTimeout(I,l))},[V,i,l,I]),R=useCallback(e=>{if(n||T)return;const{actionName:t}=e.nativeEvent;"activate"!==t&&"increment"!==t||M()},[n,T,M]);React.useEffect(()=>()=>{cancelAnimation(_),L.current&&clearTimeout(L.current)},[_]);const D=useCallback(e=>{E.value=Math.max(0,e.nativeEvent.layout.width-x-2*C)},[E,x,C]),O=useMemo(()=>{const e=s,t={damping:18,stiffness:160,mass:1},i={duration:v.motion.duration.fast,easing:Easing.out(Easing.cubic)};return Gesture.Pan().enabled(!n&&!T).minDistance(0).onStart(()=>{"worklet";k.value=_.value}).onUpdate(e=>{"worklet";_.value=Math.min(Math.max(k.value+e.translationX,0),E.value)}).onEnd(()=>{"worklet";E.value>0&&_.value>=E.value*e?(_.value=withTiming(E.value,i),runOnJS(M)()):_.value=withSpring(0,t)})},[n,T,s,_,E,k,M,v.motion.duration.fast]),z=useAnimatedStyle(()=>({transform:[{translateX:_.value}]}),[_]),F=useAnimatedStyle(()=>({width:_.value+x+C}),[_,x,C]),W=useAnimatedStyle(()=>{const e=E.value>0?E.value:1;return{opacity:Math.max(0,1-_.value/(.6*e))}},[E,_]);return _jsxs(View,{ref:t,style:[w.track,{backgroundColor:v.colors["bg-subtle"]},h,m],onLayout:D,testID:b,accessibilityRole:"adjustable",accessibilityLabel:T?g.confirmed:a??g.slide,accessibilityState:{disabled:n},"aria-disabled":n,accessibilityActions:S,onAccessibilityAction:R,children:[_jsx(Animated.View,{style:[w.fill,{backgroundColor:A,opacity:n?.5:1},F],pointerEvents:"none"}),_jsx(Animated.View,{style:[w.labelWrap,W],pointerEvents:"none",children:_jsx(Text,{variant:"body",style:[w.label,{color:v.colors["text-muted"]},p],numberOfLines:1,children:T?g.confirmed:a??g.slide})}),_jsx(GestureDetector,{gesture:O,children:_jsx(Animated.View,{style:[w.handle,{width:x,height:x,borderRadius:v.radius.pill,...smoothCorners,backgroundColor:v.colors.surface,opacity:n?.5:1,...v.shadow.card},f,z],children:d??_jsx(Chevron,{color:A,size:.5*x})})})]})});SlideToConfirm.displayName="SlideToConfirm";const buildStyles=(e,t)=>StyleSheet.create({track:{height:t.height,borderRadius:e.radius.pill,...smoothCorners,justifyContent:"center",overflow:"hidden",padding:e.space[t.pad]},fill:{position:"absolute",left:0,top:0,bottom:0,borderRadius:e.radius.pill,...smoothCorners},labelWrap:{position:"absolute",left:t.height,right:t.height},label:{textAlign:"center",includeFontPadding:!1},handle:{alignItems:"center",justifyContent:"center"}});export{SlideToConfirm};export default SlideToConfirm;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Platform,Pressable,StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{cancelAnimation,Easing,runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useControllableState}from"../../hooks/index.js";import{resolveSliderSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{Text}from"../Text/index.js";import{sliderToneInk}from"./valueText.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const VARIANT_SIZE_MAP={inset:{sm:{trackHeight:14,thumbDiameter:10},md:{trackHeight:20,thumbDiameter:14},lg:{trackHeight:26,thumbDiameter:18}},minimal:{sm:{trackHeight:2,thumbDiameter:14},md:{trackHeight:3,thumbDiameter:18},lg:{trackHeight:4,thumbDiameter:22}},bar:{sm:{trackHeight:20,thumbDiameter:20},md:{trackHeight:28,thumbDiameter:28},lg:{trackHeight:36,thumbDiameter:36}}},INSET_RING_RATIO=.3,MIN_THUMB_TOUCH=44,clamp=(e,t,a)=>Math.min(Math.max(e,t),a),snapToStep=(e,t,a,i)=>{if(i<=0)return clamp(e,t,a);const r=Math.round((e-t)/i)*i+t,n=String(i).split(".")[1]?.length??0,s=n>0?Number(r.toFixed(n)):r;return clamp(s,t,a)},BUBBLE_GAP=2,BUBBLE_CARET=8,BUBBLE_WRAP_WIDTH=160,NO_SHADOW={shadowOpacity:0,elevation:0},defaultFormatLabel=e=>String(e),Slider=forwardRef((e,t)=>{const{min:a=0,max:i=100,step:r=1,disabled:n=!1,tone:s="primary",size:o="md",variant:l="default",showLabel:u=!1,snapThumb:c=!1,formatLabel:d=defaultFormatLabel,renderLabel:m,accessibilityLabel:h,haptic:b,style:p,containerStyle:f,trackStyle:g,fillStyle:v,thumbStyle:w,labelStyle:y,thumbPressScale:S,labelShowDuration:k,labelOpacity:C,testID:x}=e;warnInvalidValue("Slider","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("Slider","size",e.size,["sm","md","lg"]),warnInvalidValue("Slider","variant",e.variant,["default","inset","minimal","bar"]);const A=useTheme(),V=useMemo(()=>{const e=resolveSliderSize(A,o);return{trackHeight:e["track-height"],thumbDiameter:e["thumb-diameter"]}},[A,o]),j=useMemo(()=>"default"===l?V:VARIANT_SIZE_MAP[l][o],[V,o,l]),M="inset"===l?j.trackHeight/2:0,_=A.settings.components.slider?.thumbPressAnimation??!1,D=S??1.1,H=k??A.motion.duration.fast,E=C??1,O=useMemo(()=>buildStyles(A,j),[A,j]),T=useMemo(()=>({damping:A.motion.spring.snappy.damping,stiffness:A.motion.spring.snappy.stiffness,mass:A.motion.spring.snappy.mass}),[A.motion.spring.snappy]),[R,I]=useState(0),W=A.colors[s],L=sliderToneInk(A,s),N=!0===e.range,[P,X]=useControllableState({value:e.value,defaultValue:e.defaultValue??(N?[a,i]:a),onChange:e.onChange}),B=useSharedValue(0),F=useSharedValue(0),z=useSharedValue(N?P[0]:P),G=useSharedValue(N?P[1]:P),J=useSharedValue(0),U=useSharedValue(0),Z=useSharedValue(1),$=useSharedValue(1),q="always"===u,K=useSharedValue(q?1:0),Q=useSharedValue(q?1:0),Y=useMemo(()=>10**(String(r).split(".")[1]?.length??0),[r]);useEffect(()=>()=>{cancelAnimation(B),cancelAnimation(F),cancelAnimation(Z),cancelAnimation($),cancelAnimation(K),cancelAnimation(Q)},[B,F,Z,$,K,Q]);const ee=useCallback((e,t)=>{const r=t-2*M;return i===a||r<=0?M:M+(e-a)/(i-a)*r},[a,i,M]),te=useCallback((e,t)=>{const n=t-2*M;if(n<=0)return a;const s=clamp((e-M)/n,0,1);return snapToStep(a+s*(i-a),a,i,r)},[a,i,r,M]),ae=useRef(!1),ie=A.motion.duration.fast,re=useRef(P);re.current=P;const ne=useRef(R);ne.current=R;const se=useCallback((e=!1)=>{const t=ne.current;if(t<=0)return;const place=t=>e?withTiming(t,{duration:ie,easing:Easing.out(Easing.cubic)}):t,a=re.current;if(N){const[e,i]=a,r=Math.min(e,i),n=Math.max(e,i);z.value=r,G.value=n,B.value=place(ee(r,t)),F.value=place(ee(n,t))}else{const e=a;z.value=e,G.value=e,B.value=place(ee(e,t))}},[N,ee,z,G,B,F,ie]),[oe,le]=useState(0),ue=useRef(!1),ce=useCallback(e=>{ae.current=e,e||(ue.current=!0,le(e=>e+1))},[]);useEffect(()=>{if(ae.current)return;const e=ue.current;ue.current=!1,se(e)},[JSON.stringify(P),R,oe,se]);const de=useCallback(e=>{const t=e.nativeEvent.layout.width;U.value=t,I(t)},[U]),me=useCallback((e,t)=>{X(N?[e,t]:e)},[N,X]),he=useCallback(()=>{const e=resolveHaptic(b,"selection");e&&triggerHaptic(e)},[b]),be=useRef(me);be.current=me;const pe=useRef(he);pe.current=he;const fe=useCallback((e,t)=>be.current(e,t),[]),ge=useCallback(()=>pe.current(),[]),ve=Math.max(0,(44-j.thumbDiameter)/2),we=ve>0?ve:void 0,ye=useCallback(e=>{const t="low"===e?B:F,s="low"===e?z:G,o="low"===e?G:z,l="low"===e?Z:$,d="low"===e?K:Q,m="low"===e,h=a,b=i,p=r,f=Y,g=N,v=D,w=_,y=!0===u,S=c,k=E,C=H,x=T,A=M,follow=e=>{"worklet";const a=U.value-2*A;if(a<=0||!Number.isFinite(e))return;const i=Math.min(Math.max(J.value+e,A),U.value-A);let r=h+(i-A)/a*(b-h);p>0&&(r=Math.round((r-h)/p)*p+h,r=Math.round(r*f)/f),r=Math.min(Math.max(r,h),b),g&&(m&&r>o.value&&(r=o.value),!m&&r<o.value&&(r=o.value)),t.value=S||b===h?b===h?A:A+(r-h)/(b-h)*a:g?m?Math.min(i,F.value):Math.max(i,B.value):i,r!==s.value&&(s.value=r,r!==h&&r!==b||runOnJS(ge)(),runOnJS(fe)(z.value,G.value))},V=Gesture.Pan().enabled(!n).minDistance(0);return(void 0===we?V:V.hitSlop(we)).onStart(()=>{"worklet";runOnJS(ce)(!0),J.value=t.value,w&&(l.value=withSpring(v,x)),y&&(d.value=withTiming(k,{duration:C,easing:Easing.out(Easing.cubic)})),runOnJS(ge)()}).onUpdate(e=>{"worklet";follow(e.translationX)}).onEnd(e=>{"worklet";follow(e.translationX),w&&(l.value=withSpring(1,x)),y&&(d.value=withTiming(0,{duration:C,easing:Easing.out(Easing.cubic)}))}).onFinalize(()=>{"worklet";runOnJS(ce)(!1)})},[n,a,i,r,Y,N,D,_,u,c,E,H,T,M,we,fe,ge,ce,B,F,z,G,Z,$,K,Q,J,U]),Se=useMemo(()=>ye("low"),[ye]),ke=useMemo(()=>ye("high"),[ye]),Ce=useCallback(e=>{if(n||N||R<=0)return;const t=clamp(e.nativeEvent.locationX,0,R),a=te(t,R);a!==z.value&&(he(),z.value=a,B.value=withTiming(ee(a,R),{duration:A.motion.duration.fast,easing:Easing.out(Easing.cubic)}),me(a,a))},[n,N,R,te,ee,me,he,B,z,A.motion.duration.fast]),xe=useCallback(e=>{if(n)return;const t="increment"===e.nativeEvent.actionName?r:-r,s=r>0?Math.round(t*Y)/Y:t;if(N){const e=Math.round((z.value+s)*Y)/Y,t=clamp(e,a,G.value);t!==z.value&&(z.value=t,B.value=ee(t,R),he(),me(t,G.value))}else{const e=Math.round((z.value+s)*Y)/Y,t=clamp(e,a,i);t!==z.value&&(z.value=t,B.value=ee(t,R),he(),me(t,t))}},[n,r,Y,N,a,i,ee,R,B,z,G,me,he]),Ae=j.thumbDiameter/2,Ve=n?A.colors["surface-disabled"]:W,je="inset"===l?{backgroundColor:Ve,borderColor:A.colors.surface,borderWidth:Math.max(2,Math.round(.3*j.thumbDiameter)),...NO_SHADOW}:"minimal"===l?{backgroundColor:Ve,borderWidth:0}:"bar"===l?{backgroundColor:"transparent",borderWidth:0,...NO_SHADOW}:{backgroundColor:A.colors.surface,borderColor:Ve},Me=useAnimatedStyle(()=>{const e=U.value;if(e<=0)return{opacity:0,transform:[{translateX:0},{scaleX:1}]};const t=n?.55:1;if(N){const a=Math.max(0,F.value-B.value+2*M);return{opacity:t,transform:[{translateX:B.value-M},{scaleX:a/e}]}}return{opacity:t,transform:[{translateX:B.value+M-e},{scaleX:1}]}}),De=useAnimatedStyle(()=>({transform:[{translateX:B.value-Ae},{scale:Z.value}]})),He=useAnimatedStyle(()=>({transform:[{translateX:F.value-Ae},{scale:$.value}]})),Ee=useAnimatedStyle(()=>({opacity:K.value})),Oe=useAnimatedStyle(()=>({opacity:Q.value})),clampDisplay=e=>clamp(e,a,i),Te=clampDisplay(N?Math.min(...P):P),Re=clampDisplay(N?Math.max(...P):P);return _jsx(View,{ref:t,style:[O.container,f,p],testID:x,accessibilityRole:"adjustable",accessibilityLabel:h,accessibilityState:{disabled:n},"aria-disabled":n,accessibilityValue:N?{min:a,max:i,now:Te,text:`${Te} to ${Re}`}:{min:a,max:i,now:Te},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:xe,children:_jsx(Pressable,{onPress:Ce,disabled:n||N,style:O.trackTouch,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:_jsxs(View,{style:O.trackWrap,onLayout:de,children:[_jsxs(View,{style:O.trackClip,pointerEvents:"none",children:[_jsx(View,{style:[O.track,{backgroundColor:n?A.colors["surface-disabled"]:A.colors.border},g]}),_jsx(Animated.View,{style:[O.fill,{backgroundColor:n?A.colors["surface-disabled"]:W},v,Me]})]}),_jsx(GestureDetector,{gesture:Se,children:_jsx(Animated.View,{style:[O.thumb,{width:j.thumbDiameter,height:j.thumbDiameter,borderRadius:Ae,...smoothCorners,opacity:n?.55:1},je,w,De],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:u?_jsxs(Animated.View,{style:[O.bubbleWrap,Ee],pointerEvents:"none",children:[_jsx(View,{style:[O.bubble,{backgroundColor:W}],children:m?m(Te):_jsx(Text,{variant:"caption",weight:"semibold",style:[{color:L},y],numberOfLines:1,children:d(Te)})}),_jsx(View,{style:[O.bubbleCaret,{backgroundColor:W}]})]}):null})}),N?_jsx(GestureDetector,{gesture:ke,children:_jsx(Animated.View,{style:[O.thumb,{width:j.thumbDiameter,height:j.thumbDiameter,borderRadius:Ae,...smoothCorners,opacity:n?.55:1},je,w,He],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:u?_jsxs(Animated.View,{style:[O.bubbleWrap,Oe],pointerEvents:"none",children:[_jsx(View,{style:[O.bubble,{backgroundColor:W}],children:m?m(Re):_jsx(Text,{variant:"caption",weight:"semibold",style:[{color:L},y],numberOfLines:1,children:d(Re)})}),_jsx(View,{style:[O.bubbleCaret,{backgroundColor:W}]})]}):null})}):null]})})})});Slider.displayName="Slider";const buildStyles=(e,t)=>{const a=e.shadow.elevated,i=Math.max(t.thumbDiameter,t.trackHeight),r=i/2+e.space.xs;return StyleSheet.create({container:{width:"100%",paddingVertical:r,justifyContent:"center"},trackTouch:{width:"100%",justifyContent:"center"},trackWrap:{width:"100%",height:i,justifyContent:"center"},trackClip:{position:"absolute",left:0,right:0,height:t.trackHeight,top:(i-t.trackHeight)/2,borderRadius:t.trackHeight/2,...smoothCorners,overflow:"hidden"},track:{position:"absolute",top:0,right:0,bottom:0,left:0,borderRadius:t.trackHeight/2,...smoothCorners},fill:{position:"absolute",top:0,left:0,width:"100%",height:t.trackHeight,borderRadius:t.trackHeight/2,...smoothCorners,transformOrigin:"left"},thumb:{position:"absolute",top:(i-t.thumbDiameter)/2,left:0,borderWidth:2,shadowColor:a.shadowColor,shadowOffset:a.shadowOffset,shadowOpacity:a.shadowOpacity,shadowRadius:a.shadowRadius,elevation:a.elevation,alignItems:"center",justifyContent:"center"},bubbleWrap:{position:"absolute",bottom:t.thumbDiameter+2,left:t.thumbDiameter/2-80,width:160,alignItems:"center"},bubbleCaret:{width:8,height:8,marginTop:-5,borderRadius:e.radius.none,...smoothCorners,transform:[{rotate:"45deg"}]},bubble:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xxs,borderRadius:e.radius.md,...smoothCorners,minWidth:36,alignItems:"center",justifyContent:"center",...Platform.select({ios:{shadowColor:e.shadow.card.shadowColor,shadowOffset:e.shadow.card.shadowOffset,shadowOpacity:e.shadow.card.shadowOpacity,shadowRadius:e.shadow.card.shadowRadius},android:{elevation:e.shadow.card.elevation},default:{}})}})};export{Slider};export default Slider;
|
|
1
|
+
"use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Platform,Pressable,StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{cancelAnimation,Easing,runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useControllableState}from"../../hooks/index.js";import{resolveSliderSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{Text}from"../Text/index.js";import{sliderToneInk}from"./valueText.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const VARIANT_SIZE_MAP={inset:{sm:{trackHeight:14,thumbDiameter:10},md:{trackHeight:20,thumbDiameter:14},lg:{trackHeight:26,thumbDiameter:18}},minimal:{sm:{trackHeight:2,thumbDiameter:14},md:{trackHeight:3,thumbDiameter:18},lg:{trackHeight:4,thumbDiameter:22}},bar:{sm:{trackHeight:20,thumbDiameter:20},md:{trackHeight:28,thumbDiameter:28},lg:{trackHeight:36,thumbDiameter:36}}},INSET_RING_RATIO=.3,MIN_THUMB_TOUCH=44,clamp=(e,t,a)=>Math.min(Math.max(e,t),a),snapToStep=(e,t,a,i)=>{if(i<=0)return clamp(e,t,a);const r=Math.round((e-t)/i)*i+t,n=String(i).split(".")[1]?.length??0,s=n>0?Number(r.toFixed(n)):r;return clamp(s,t,a)},BUBBLE_GAP=2,BUBBLE_CARET=8,BUBBLE_WRAP_WIDTH=160,NO_SHADOW={shadowOpacity:0,elevation:0},defaultFormatLabel=e=>String(e),Slider=forwardRef((e,t)=>{const{min:a=0,max:i=100,step:r=1,disabled:n=!1,tone:s="primary",size:o="md",variant:l="default",showLabel:u=!1,snapThumb:c=!1,formatLabel:d=defaultFormatLabel,renderLabel:m,accessibilityLabel:h,haptic:b,style:p,containerStyle:f,trackStyle:g,fillStyle:v,thumbStyle:w,labelStyle:y,thumbPressScale:S,labelShowDuration:k,labelOpacity:C,testID:x}=e;warnInvalidValue("Slider","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("Slider","size",e.size,["sm","md","lg"]),warnInvalidValue("Slider","variant",e.variant,["default","inset","minimal","bar"]);const A=useTheme(),V=useMemo(()=>{const e=resolveSliderSize(A,o);return{trackHeight:e["track-height"],thumbDiameter:e["thumb-diameter"]}},[A,o]),j=useMemo(()=>"default"===l?V:VARIANT_SIZE_MAP[l][o],[V,o,l]),M="inset"===l?j.trackHeight/2:0,_=A.settings.components.slider?.thumbPressAnimation??!1,D=S??1.1,H=k??A.motion.duration.fast,E=C??1,O=useMemo(()=>buildStyles(A,j),[A,j]),T=useMemo(()=>({damping:A.motion.spring.snappy.damping,stiffness:A.motion.spring.snappy.stiffness,mass:A.motion.spring.snappy.mass}),[A.motion.spring.snappy]),[R,I]=useState(0),W=A.colors[s],L=sliderToneInk(A,s),N=!0===e.range,[P,X]=useControllableState({value:e.value,defaultValue:e.defaultValue??(N?[a,i]:a),onChange:e.onChange}),B=useSharedValue(0),F=useSharedValue(0),z=useSharedValue(N?P[0]:P),G=useSharedValue(N?P[1]:P),J=useSharedValue(0),U=useSharedValue(0),Z=useSharedValue(1),$=useSharedValue(1),q="always"===u,K=useSharedValue(q?1:0),Q=useSharedValue(q?1:0),Y=useMemo(()=>10**(String(r).split(".")[1]?.length??0),[r]);useEffect(()=>()=>{cancelAnimation(B),cancelAnimation(F),cancelAnimation(Z),cancelAnimation($),cancelAnimation(K),cancelAnimation(Q)},[B,F,Z,$,K,Q]);const ee=useCallback((e,t)=>{const r=t-2*M;return i===a||r<=0?M:M+(e-a)/(i-a)*r},[a,i,M]),te=useCallback((e,t)=>{const n=t-2*M;if(n<=0)return a;const s=clamp((e-M)/n,0,1);return snapToStep(a+s*(i-a),a,i,r)},[a,i,r,M]),ae=useRef(!1),ie=A.motion.duration.fast,re=useRef(P);re.current=P;const ne=useRef(R);ne.current=R;const se=useCallback((e=!1)=>{const t=ne.current;if(t<=0)return;const place=t=>e?withTiming(t,{duration:ie,easing:Easing.out(Easing.cubic)}):t,a=re.current;if(N){const[e,i]=a,r=Math.min(e,i),n=Math.max(e,i);z.value=r,G.value=n,B.value=place(ee(r,t)),F.value=place(ee(n,t))}else{const e=a;z.value=e,G.value=e,B.value=place(ee(e,t))}},[N,ee,z,G,B,F,ie]),[oe,le]=useState(0),ue=useRef(!1),ce=useCallback(e=>{ae.current=e,e||(ue.current=!0,le(e=>e+1))},[]);useEffect(()=>{if(ae.current)return;const e=ue.current;ue.current=!1,se(e)},[JSON.stringify(P),R,oe,se]);const de=useCallback(e=>{const t=e.nativeEvent.layout.width;U.value=t,I(t)},[U]),me=useCallback((e,t)=>{X(N?[e,t]:e)},[N,X]),he=useCallback(()=>{const e=resolveHaptic(b,"selection");e&&triggerHaptic(e)},[b]),be=useRef(me);be.current=me;const pe=useRef(he);pe.current=he;const fe=useCallback((e,t)=>be.current(e,t),[]),ge=useCallback(()=>pe.current(),[]),ve=Math.max(0,(44-j.thumbDiameter)/2),we=ve>0?ve:void 0,ye=useCallback(e=>{const t="low"===e?B:F,s="low"===e?z:G,o="low"===e?G:z,l="low"===e?Z:$,d="low"===e?K:Q,m="low"===e,h=a,b=i,p=r,f=Y,g=N,v=D,w=_,y=!0===u,S=c,k=E,C=H,x=T,A=M,follow=e=>{"worklet";const a=U.value-2*A;if(a<=0||!Number.isFinite(e))return;const i=Math.min(Math.max(J.value+e,A),U.value-A);let r=h+(i-A)/a*(b-h);p>0&&(r=Math.round((r-h)/p)*p+h,r=Math.round(r*f)/f),r=Math.min(Math.max(r,h),b),g&&(m&&r>o.value&&(r=o.value),!m&&r<o.value&&(r=o.value)),t.value=S||b===h?b===h?A:A+(r-h)/(b-h)*a:g?m?Math.min(i,F.value):Math.max(i,B.value):i,r!==s.value&&(s.value=r,r!==h&&r!==b||runOnJS(ge)(),runOnJS(fe)(z.value,G.value))},V=Gesture.Pan().enabled(!n).minDistance(0);return(void 0===we?V:V.hitSlop(we)).onStart(()=>{"worklet";runOnJS(ce)(!0),J.value=t.value,w&&(l.value=withSpring(v,x)),y&&(d.value=withTiming(k,{duration:C,easing:Easing.out(Easing.cubic)})),runOnJS(ge)()}).onUpdate(e=>{"worklet";follow(e.translationX)}).onEnd(e=>{"worklet";follow(e.translationX),w&&(l.value=withSpring(1,x)),y&&(d.value=withTiming(0,{duration:C,easing:Easing.out(Easing.cubic)}))}).onFinalize(()=>{"worklet";runOnJS(ce)(!1)})},[n,a,i,r,Y,N,D,_,u,c,E,H,T,M,we,fe,ge,ce,B,F,z,G,Z,$,K,Q,J,U]),Se=useMemo(()=>ye("low"),[ye]),ke=useMemo(()=>ye("high"),[ye]),Ce=useCallback(e=>{if(n||N||R<=0)return;const t=clamp(e.nativeEvent.locationX,0,R),a=te(t,R);a!==z.value&&(he(),z.value=a,B.value=withTiming(ee(a,R),{duration:A.motion.duration.fast,easing:Easing.out(Easing.cubic)}),me(a,a))},[n,N,R,te,ee,me,he,B,z,A.motion.duration.fast]),xe=useCallback(e=>{if(n)return;const t="increment"===e.nativeEvent.actionName?r:-r,s=r>0?Math.round(t*Y)/Y:t;if(N){const e=Math.round((z.value+s)*Y)/Y,t=clamp(e,a,G.value);t!==z.value&&(z.value=t,B.value=ee(t,R),he(),me(t,G.value))}else{const e=Math.round((z.value+s)*Y)/Y,t=clamp(e,a,i);t!==z.value&&(z.value=t,B.value=ee(t,R),he(),me(t,t))}},[n,r,Y,N,a,i,ee,R,B,z,G,me,he]),Ae=j.thumbDiameter/2,Ve=n?A.colors["surface-disabled"]:W,je="inset"===l?{backgroundColor:Ve,borderColor:A.colors.surface,borderWidth:Math.max(2,Math.round(.3*j.thumbDiameter)),...NO_SHADOW}:"minimal"===l?{backgroundColor:Ve,borderWidth:0}:"bar"===l?{backgroundColor:"transparent",borderWidth:0,...NO_SHADOW}:{backgroundColor:A.colors.surface,borderColor:Ve},Me=useAnimatedStyle(()=>{const e=U.value;if(e<=0)return{opacity:0,transform:[{translateX:0},{scaleX:1}]};const t=n?.55:1;if(N){const a=Math.max(0,F.value-B.value+2*M);return{opacity:t,transform:[{translateX:B.value-M},{scaleX:a/e}]}}return{opacity:t,transform:[{translateX:B.value+M-e},{scaleX:1}]}},[U,n,N,F,B,M]),De=useAnimatedStyle(()=>({transform:[{translateX:B.value-Ae},{scale:Z.value}]}),[B,Ae,Z]),He=useAnimatedStyle(()=>({transform:[{translateX:F.value-Ae},{scale:$.value}]}),[F,Ae,$]),Ee=useAnimatedStyle(()=>({opacity:K.value}),[K]),Oe=useAnimatedStyle(()=>({opacity:Q.value}),[Q]),clampDisplay=e=>clamp(e,a,i),Te=clampDisplay(N?Math.min(...P):P),Re=clampDisplay(N?Math.max(...P):P);return _jsx(View,{ref:t,style:[O.container,f,p],testID:x,accessibilityRole:"adjustable",accessibilityLabel:h,accessibilityState:{disabled:n},"aria-disabled":n,accessibilityValue:N?{min:a,max:i,now:Te,text:`${Te} to ${Re}`}:{min:a,max:i,now:Te},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:xe,children:_jsx(Pressable,{onPress:Ce,disabled:n||N,style:O.trackTouch,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:_jsxs(View,{style:O.trackWrap,onLayout:de,children:[_jsxs(View,{style:O.trackClip,pointerEvents:"none",children:[_jsx(View,{style:[O.track,{backgroundColor:n?A.colors["surface-disabled"]:A.colors.border},g]}),_jsx(Animated.View,{style:[O.fill,{backgroundColor:n?A.colors["surface-disabled"]:W},v,Me]})]}),_jsx(GestureDetector,{gesture:Se,children:_jsx(Animated.View,{style:[O.thumb,{width:j.thumbDiameter,height:j.thumbDiameter,borderRadius:Ae,...smoothCorners,opacity:n?.55:1},je,w,De],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:u?_jsxs(Animated.View,{style:[O.bubbleWrap,Ee],pointerEvents:"none",children:[_jsx(View,{style:[O.bubble,{backgroundColor:W}],children:m?m(Te):_jsx(Text,{variant:"caption",weight:"semibold",style:[{color:L},y],numberOfLines:1,children:d(Te)})}),_jsx(View,{style:[O.bubbleCaret,{backgroundColor:W}]})]}):null})}),N?_jsx(GestureDetector,{gesture:ke,children:_jsx(Animated.View,{style:[O.thumb,{width:j.thumbDiameter,height:j.thumbDiameter,borderRadius:Ae,...smoothCorners,opacity:n?.55:1},je,w,He],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:u?_jsxs(Animated.View,{style:[O.bubbleWrap,Oe],pointerEvents:"none",children:[_jsx(View,{style:[O.bubble,{backgroundColor:W}],children:m?m(Re):_jsx(Text,{variant:"caption",weight:"semibold",style:[{color:L},y],numberOfLines:1,children:d(Re)})}),_jsx(View,{style:[O.bubbleCaret,{backgroundColor:W}]})]}):null})}):null]})})})});Slider.displayName="Slider";const buildStyles=(e,t)=>{const a=e.shadow.elevated,i=Math.max(t.thumbDiameter,t.trackHeight),r=i/2+e.space.xs;return StyleSheet.create({container:{width:"100%",paddingVertical:r,justifyContent:"center"},trackTouch:{width:"100%",justifyContent:"center"},trackWrap:{width:"100%",height:i,justifyContent:"center"},trackClip:{position:"absolute",left:0,right:0,height:t.trackHeight,top:(i-t.trackHeight)/2,borderRadius:t.trackHeight/2,...smoothCorners,overflow:"hidden"},track:{position:"absolute",top:0,right:0,bottom:0,left:0,borderRadius:t.trackHeight/2,...smoothCorners},fill:{position:"absolute",top:0,left:0,width:"100%",height:t.trackHeight,borderRadius:t.trackHeight/2,...smoothCorners,transformOrigin:"left"},thumb:{position:"absolute",top:(i-t.thumbDiameter)/2,left:0,borderWidth:2,shadowColor:a.shadowColor,shadowOffset:a.shadowOffset,shadowOpacity:a.shadowOpacity,shadowRadius:a.shadowRadius,elevation:a.elevation,alignItems:"center",justifyContent:"center"},bubbleWrap:{position:"absolute",bottom:t.thumbDiameter+2,left:t.thumbDiameter/2-80,width:160,alignItems:"center"},bubbleCaret:{width:8,height:8,marginTop:-5,borderRadius:e.radius.none,...smoothCorners,transform:[{rotate:"45deg"}]},bubble:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xxs,borderRadius:e.radius.md,...smoothCorners,minWidth:36,alignItems:"center",justifyContent:"center",...Platform.select({ios:{shadowColor:e.shadow.card.shadowColor,shadowOffset:e.shadow.card.shadowOffset,shadowOpacity:e.shadow.card.shadowOpacity,shadowRadius:e.shadow.card.shadowRadius},android:{elevation:e.shadow.card.elevation},default:{}})}})};export{Slider};export default Slider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{cancelAnimation,measure,runOnJS,scrollTo,useAnimatedRef,useAnimatedScrollHandler,useAnimatedStyle,useFrameCallback,useSharedValue,withSpring}from"react-native-reanimated";import{useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{useScrollHost}from"../Screen/ScrollHost.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SORTABLE_LIST_LABELS=Object.freeze({moveUp:"Move up",moveDown:"Move down"});const LONG_PRESS_MS=350,EDGE_PX=48,SCROLL_STEP_PX=12,SCROLL_SLACK_PX=1,SPRING_CONFIG={damping:22,stiffness:260,mass:1},ACTION_STEP={moveUp:-1,moveDown:1},noop=e=>{};export function moveItem(e,t,a){const l=e.slice();if(t<0||t>=l.length)return l;const[o]=l.splice(t,1);return l.splice(a,0,o),l}export function topOf(e,t){"worklet";let a=0;for(let l=0;l<t;l++)a+=e[l]??0;return a}export function slotTop(e,t,a){"worklet";let l=0,o=0;for(let r=0;r<e.length&&o<a;r++)r!==t&&(l+=e[r]??0,o++);return l}export function dropIndex(e,t,a){"worklet";const l=topOf(e,t)+(e[t]??0)/2+a;let o=0,r=0;for(let a=0;a<e.length;a++){const s=e[a]??0;a!==t&&r+s/2<l&&o++,r+=s}return o}export function rowShifts(e,t,a){const l=[];let o=0;for(const t of e)l.push(o),o+=t;const r=e.map(()=>0),s=moveItem(e.map((e,t)=>t),t,a);let n=0;for(const t of s)r[t]=n-(l[t]??0),n+=e[t]??0;return r}const buildStyles=e=>StyleSheet.create({handleRow:{flexDirection:"row",alignItems:"center"},handle:{paddingHorizontal:e.space.sm,paddingVertical:e.space.md,gap:e.space.xxs},bar:{width:e.space.md,height:e.space.xxs,backgroundColor:e.colors["text-muted"]},body:{flex:1}});function SortableRow({rowKey:e,index:t,count:a,shift:l,isActive:o,dragging:r,handle:s,disabled:n,shared:u,callbacks:i,labels:c,children:d}){const m=useTheme(),v=useMemo(()=>buildStyles(m),[m]),h=useSharedValue(0);useEffect(()=>{h.value=r&&!o?withSpring(l,SPRING_CONFIG):l},[r,o,l,h]),useEffect(()=>()=>{cancelAnimation(h)},[h]);const S=useAnimatedStyle(()=>({transform:[{translateY:o?u.dragY.value:h.value}],zIndex:o?1:0})),f=useMemo(()=>{const{dragIndex:e,dropTo:a,dragY:l,translation:o,absoluteY:r,scrollY:c,scrollStart:d,hostOffset:m,hostStart:v,hostTarget:h,heights:S}=u,{onLift:f,onDrop:g,onSettled:p}=i,b=Gesture.Pan().enabled(!n).onStart(s=>{"worklet";r.value=s.absoluteY,e.value=t,a.value=t,d.value=c.value,v.value=m.value,h.value=m.value,o.value=0,l.value=0,runOnJS(f)(t)}).onUpdate(a=>{"worklet";e.value===t&&(o.value=a.translationY,r.value=a.absoluteY)}).onFinalize(()=>{"worklet";if(e.value!==t)return;const o=a.value,r=S.value;e.value=-1,l.value=topOf(r,t)+l.value-slotTop(r,t,o),l.value=withSpring(0,SPRING_CONFIG,e=>{"worklet";e&&runOnJS(p)()}),runOnJS(g)(t,o)});return s?b:b.activateAfterLongPress(350)},[n,s,t,i,u]),g=n?[]:[...t>0?[{name:"moveUp",label:c.moveUp}]:[],...t<a-1?[{name:"moveDown",label:c.moveDown}]:[]];return _jsx(Animated.View,{style:S,onLayout:t=>i.onHeight(e,t.nativeEvent.layout.height),accessibilityActions:g,onAccessibilityAction:e=>{if(n)return;const l=t+(ACTION_STEP[e.nativeEvent.actionName]??0);l!==t&&l>=0&&l<a&&i.onMove(t,l)},testID:`sortable-row-${e}`,children:s?_jsxs(View,{style:v.handleRow,children:[_jsx(GestureDetector,{gesture:f,children:_jsxs(View,{style:v.handle,children:[_jsx(View,{style:v.bar}),_jsx(View,{style:v.bar}),_jsx(View,{style:v.bar})]})}),_jsx(View,{style:v.body,children:d})]}):_jsx(GestureDetector,{gesture:f,children:_jsx(View,{children:d})})})}export function SortableList(e){const{data:t,keyExtractor:a,renderItem:l,onReorder:o,handle:r=!1,disabled:s=!1,accessibilityLabel:n,labels:u,testID:i}=e,c=useMemo(()=>({...DEFAULT_SORTABLE_LIST_LABELS,...u}),[u]),d=useMemo(()=>t.map((e,t)=>({key:a(e,t),item:e})),[t,a]),m=useMemo(()=>d.map(e=>e.key),[d]),v=useAnimatedRef(),h=useSharedValue(0),S=useSharedValue(0),f=useSharedValue(0),g=useScrollHost(),p=useSharedValue(0),b=null!==g,x=g?.top??p,w=g?.bottom??p,y=g?.offset??p,_=g?.maxOffset??p,k=g?.scrollTo??noop,A=useSharedValue(0),L=useSharedValue(0),O=useSharedValue(0),V=useSharedValue(0),I=useSharedValue(-1),T=useSharedValue(-1),C=useSharedValue(0),E=useSharedValue([]),j=useRef(new Map),M=useRef(m),[R,D]=useState(null),Y=useCallback(()=>{E.value=M.current.map(e=>j.current.get(e)??0)},[E]);useEffect(()=>{M.current=m,Y()},[m,Y]),useEffect(()=>()=>{cancelAnimation(C)},[C]);const G=useCallback(e=>{D(t=>t?.dragging?{...t,to:e}:t)},[]),P=useFrameCallback(()=>{"worklet";const e=I.value;if(e<0)return;const t=measure(v);if(t){const e=b?Math.max(t.pageY,x.value):t.pageY,a=b?Math.min(t.pageY+t.height,w.value):t.pageY+t.height,l=Math.max(0,f.value-t.height-1);V.value<e+48?h.value>1?scrollTo(v,0,Math.max(0,h.value-12),!1):b&&L.value>0&&(L.value=Math.max(0,L.value-12),runOnJS(k)(L.value)):V.value>a-48&&(h.value<l?scrollTo(v,0,Math.min(l,h.value+12),!1):b&&L.value<_.value&&(L.value=Math.min(_.value,L.value+12),runOnJS(k)(L.value)))}C.value=O.value+h.value-S.value+y.value-A.value;const a=dropIndex(E.value,e,C.value);a!==T.value&&(T.value=a,runOnJS(G)(a))},!1),N=useCallback(e=>{triggerHaptic("longPress"),P.setActive(!0),D({key:m[e]??"",from:e,to:e,dragging:!0})},[P,m]),H=useCallback((e,t)=>{P.setActive(!1),D(e=>e?{...e,to:t,dragging:!1}:e),t!==e&&o(moveItem(m,e,t))},[P,m,o]),F=useCallback(()=>{D(e=>e&&!e.dragging?null:e)},[]),J=useCallback((e,t)=>{o(moveItem(m,e,t))},[m,o]),U=useCallback((e,t)=>{j.current.set(e,t),Y()},[Y]),z=useAnimatedScrollHandler({onScroll:e=>{"worklet";h.value=e.contentOffset.y}}),B=useCallback((e,t)=>{f.value=t},[f]),K=useMemo(()=>({scrollRef:v,scrollY:h,scrollStart:S,hostOffset:y,hostStart:A,hostTarget:L,translation:O,absoluteY:V,dragIndex:I,dropTo:T,dragY:C,heights:E}),[v,h,S,y,A,L,O,V,I,T,C,E]),X=useMemo(()=>({onLift:N,onDrop:H,onSettled:F,onMove:J,onHeight:U}),[N,H,F,J,U]),$=!0===R?.dragging,q=$&&R?rowShifts(m.map(e=>j.current.get(e)??0),R.from,R.to):null;return _jsx(Animated.ScrollView,{ref:v,onScroll:z,onContentSizeChange:B,scrollEventThrottle:16,scrollEnabled:!$,accessibilityLabel:n,testID:i,children:d.map((e,t)=>{const a=R?.key===e.key;return _jsx(SortableRow,{rowKey:e.key,index:t,count:d.length,shift:q?.[t]??0,isActive:a,dragging:$,handle:r,disabled:s,shared:K,callbacks:X,labels:c,children:l({item:e.item,index:t,isActive:a})},e.key)})})}SortableList.displayName="SortableList";export default SortableList;
|
|
1
|
+
"use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{cancelAnimation,measure,runOnJS,scrollTo,useAnimatedRef,useAnimatedScrollHandler,useAnimatedStyle,useFrameCallback,useSharedValue,withSpring}from"react-native-reanimated";import{useTheme}from"../../theme/index.js";import{triggerHaptic}from"../../utils/index.js";import{useScrollHost}from"../Screen/ScrollHost.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SORTABLE_LIST_LABELS=Object.freeze({moveUp:"Move up",moveDown:"Move down"});const LONG_PRESS_MS=350,EDGE_PX=48,SCROLL_STEP_PX=12,SCROLL_SLACK_PX=1,SPRING_CONFIG={damping:22,stiffness:260,mass:1},ACTION_STEP={moveUp:-1,moveDown:1},noop=e=>{};export function moveItem(e,t,a){const l=e.slice();if(t<0||t>=l.length)return l;const[o]=l.splice(t,1);return l.splice(a,0,o),l}export function topOf(e,t){"worklet";let a=0;for(let l=0;l<t;l++)a+=e[l]??0;return a}export function slotTop(e,t,a){"worklet";let l=0,o=0;for(let r=0;r<e.length&&o<a;r++)r!==t&&(l+=e[r]??0,o++);return l}export function dropIndex(e,t,a){"worklet";const l=topOf(e,t)+(e[t]??0)/2+a;let o=0,r=0;for(let a=0;a<e.length;a++){const s=e[a]??0;a!==t&&r+s/2<l&&o++,r+=s}return o}export function rowShifts(e,t,a){const l=[];let o=0;for(const t of e)l.push(o),o+=t;const r=e.map(()=>0),s=moveItem(e.map((e,t)=>t),t,a);let n=0;for(const t of s)r[t]=n-(l[t]??0),n+=e[t]??0;return r}const buildStyles=e=>StyleSheet.create({handleRow:{flexDirection:"row",alignItems:"center"},handle:{paddingHorizontal:e.space.sm,paddingVertical:e.space.md,gap:e.space.xxs},bar:{width:e.space.md,height:e.space.xxs,backgroundColor:e.colors["text-muted"]},body:{flex:1}});function SortableRow({rowKey:e,index:t,count:a,shift:l,isActive:o,dragging:r,handle:s,disabled:n,shared:u,callbacks:i,labels:c,children:d}){const m=useTheme(),v=useMemo(()=>buildStyles(m),[m]),h=useSharedValue(0);useEffect(()=>{h.value=r&&!o?withSpring(l,SPRING_CONFIG):l},[r,o,l,h]),useEffect(()=>()=>{cancelAnimation(h)},[h]);const S=useAnimatedStyle(()=>({transform:[{translateY:o?u.dragY.value:h.value}],zIndex:o?1:0}),[o,u,h]),f=useMemo(()=>{const{dragIndex:e,dropTo:a,dragY:l,translation:o,absoluteY:r,scrollY:c,scrollStart:d,hostOffset:m,hostStart:v,hostTarget:h,heights:S}=u,{onLift:f,onDrop:g,onSettled:p}=i,b=Gesture.Pan().enabled(!n).onStart(s=>{"worklet";r.value=s.absoluteY,e.value=t,a.value=t,d.value=c.value,v.value=m.value,h.value=m.value,o.value=0,l.value=0,runOnJS(f)(t)}).onUpdate(a=>{"worklet";e.value===t&&(o.value=a.translationY,r.value=a.absoluteY)}).onFinalize(()=>{"worklet";if(e.value!==t)return;const o=a.value,r=S.value;e.value=-1,l.value=topOf(r,t)+l.value-slotTop(r,t,o),l.value=withSpring(0,SPRING_CONFIG,e=>{"worklet";e&&runOnJS(p)()}),runOnJS(g)(t,o)});return s?b:b.activateAfterLongPress(350)},[n,s,t,i,u]),g=n?[]:[...t>0?[{name:"moveUp",label:c.moveUp}]:[],...t<a-1?[{name:"moveDown",label:c.moveDown}]:[]];return _jsx(Animated.View,{style:S,onLayout:t=>i.onHeight(e,t.nativeEvent.layout.height),accessibilityActions:g,onAccessibilityAction:e=>{if(n)return;const l=t+(ACTION_STEP[e.nativeEvent.actionName]??0);l!==t&&l>=0&&l<a&&i.onMove(t,l)},testID:`sortable-row-${e}`,children:s?_jsxs(View,{style:v.handleRow,children:[_jsx(GestureDetector,{gesture:f,children:_jsxs(View,{style:v.handle,children:[_jsx(View,{style:v.bar}),_jsx(View,{style:v.bar}),_jsx(View,{style:v.bar})]})}),_jsx(View,{style:v.body,children:d})]}):_jsx(GestureDetector,{gesture:f,children:_jsx(View,{children:d})})})}export function SortableList(e){const{data:t,keyExtractor:a,renderItem:l,onReorder:o,handle:r=!1,disabled:s=!1,accessibilityLabel:n,labels:u,testID:i}=e,c=useMemo(()=>({...DEFAULT_SORTABLE_LIST_LABELS,...u}),[u]),d=useMemo(()=>t.map((e,t)=>({key:a(e,t),item:e})),[t,a]),m=useMemo(()=>d.map(e=>e.key),[d]),v=useAnimatedRef(),h=useSharedValue(0),S=useSharedValue(0),f=useSharedValue(0),g=useScrollHost(),p=useSharedValue(0),b=null!==g,x=g?.top??p,w=g?.bottom??p,y=g?.offset??p,_=g?.maxOffset??p,k=g?.scrollTo??noop,A=useSharedValue(0),L=useSharedValue(0),O=useSharedValue(0),V=useSharedValue(0),I=useSharedValue(-1),T=useSharedValue(-1),C=useSharedValue(0),E=useSharedValue([]),j=useRef(new Map),M=useRef(m),[R,D]=useState(null),Y=useCallback(()=>{E.value=M.current.map(e=>j.current.get(e)??0)},[E]);useEffect(()=>{M.current=m,Y()},[m,Y]),useEffect(()=>()=>{cancelAnimation(C)},[C]);const G=useCallback(e=>{D(t=>t?.dragging?{...t,to:e}:t)},[]),P=useFrameCallback(()=>{"worklet";const e=I.value;if(e<0)return;const t=measure(v);if(t){const e=b?Math.max(t.pageY,x.value):t.pageY,a=b?Math.min(t.pageY+t.height,w.value):t.pageY+t.height,l=Math.max(0,f.value-t.height-1);V.value<e+48?h.value>1?scrollTo(v,0,Math.max(0,h.value-12),!1):b&&L.value>0&&(L.value=Math.max(0,L.value-12),runOnJS(k)(L.value)):V.value>a-48&&(h.value<l?scrollTo(v,0,Math.min(l,h.value+12),!1):b&&L.value<_.value&&(L.value=Math.min(_.value,L.value+12),runOnJS(k)(L.value)))}C.value=O.value+h.value-S.value+y.value-A.value;const a=dropIndex(E.value,e,C.value);a!==T.value&&(T.value=a,runOnJS(G)(a))},!1),N=useCallback(e=>{triggerHaptic("longPress"),P.setActive(!0),D({key:m[e]??"",from:e,to:e,dragging:!0})},[P,m]),H=useCallback((e,t)=>{P.setActive(!1),D(e=>e?{...e,to:t,dragging:!1}:e),t!==e&&o(moveItem(m,e,t))},[P,m,o]),F=useCallback(()=>{D(e=>e&&!e.dragging?null:e)},[]),J=useCallback((e,t)=>{o(moveItem(m,e,t))},[m,o]),U=useCallback((e,t)=>{j.current.set(e,t),Y()},[Y]),z=useAnimatedScrollHandler({onScroll:e=>{"worklet";h.value=e.contentOffset.y}}),B=useCallback((e,t)=>{f.value=t},[f]),K=useMemo(()=>({scrollRef:v,scrollY:h,scrollStart:S,hostOffset:y,hostStart:A,hostTarget:L,translation:O,absoluteY:V,dragIndex:I,dropTo:T,dragY:C,heights:E}),[v,h,S,y,A,L,O,V,I,T,C,E]),X=useMemo(()=>({onLift:N,onDrop:H,onSettled:F,onMove:J,onHeight:U}),[N,H,F,J,U]),$=!0===R?.dragging,q=$&&R?rowShifts(m.map(e=>j.current.get(e)??0),R.from,R.to):null;return _jsx(Animated.ScrollView,{ref:v,onScroll:z,onContentSizeChange:B,scrollEventThrottle:16,scrollEnabled:!$,accessibilityLabel:n,testID:i,children:d.map((e,t)=>{const a=R?.key===e.key;return _jsx(SortableRow,{rowKey:e.key,index:t,count:d.length,shift:q?.[t]??0,isActive:a,dragging:$,handle:r,disabled:s,shared:K,callbacks:X,labels:c,children:l({item:e.item,index:t,isActive:a})},e.key)})})}SortableList.displayName="SortableList";export default SortableList;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useCallback,useEffect,useMemo,useRef}from"react";import{Dimensions,Pressable,StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{cancelAnimation,runOnJS,useAnimatedStyle,useSharedValue,withSpring}from"react-native-reanimated";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const SPRING_CONFIG={damping:22,stiffness:260,mass:1},DRAG_ACTIVATION_OFFSET=10,RUBBER_BAND_FACTOR=.35,FAIL_OFFSET_Y=15,ACTION_ICON_SIZE=20,toneToBg=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;default:return e.colors.neutral}},toneToOnColor=(e,t)=>{switch(t){case"primary":return e.colors["on-primary"];case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];default:return e.colors["on-neutral"]}},Swipeable=e=>{const{children:t,leftActions:n,rightActions:o,threshold:i,fullSwipeThreshold:r,onSwipeOpen:s,onSwipeClose:a,disabled:l=!1,haptic:c,containerStyle:u,contentStyle:d,actionStyle:m,accessibilityLabel:h,testID:p}=e,S=useTheme(),w=i??80,b=r??200,f=useMemo(()=>buildStyles(S),[S]),g=useMemo(()=>buildActionStyles(S),[S]),y=!!n&&n.length>0,v=!!o&&o.length>0,x=Dimensions.get("window").width,I=y?w*(n?.length??0):0,A=v?w*(o?.length??0):0,_=useSharedValue(0),C=useSharedValue(0),O=useRef(null);useEffect(()=>()=>{cancelAnimation(_),cancelAnimation(C)},[_,C]);const j=useCallback(e=>{O.current!==e&&(O.current=e,s?.(e))},[s]),G=useCallback(()=>{null!==O.current&&(O.current=null,a?.())},[a]),N=useCallback(e=>{const t="left"===e?n:o,i=t?.[0];i&&(!1!==c&&triggerHaptic("notificationSuccess"),i.onPress(),_.value=withSpring(0,SPRING_CONFIG),O.current=null,a?.())},[n,o,_,a,c]),R=useCallback(()=>{_.value=withSpring(0,SPRING_CONFIG),G()},[_,G]),k=useCallback(e=>{const t=resolveHaptic(c,"selection");t&&triggerHaptic(t),e.onPress(),R()},[R,c]),P=useMemo(()=>{const e=I,t=A,n=b,o=-b,i=x,r=-x,s=w,a=y,c=v;return Gesture.Pan().enabled(!l).withTestId(p?`${p}-gesture`:"swipeable-gesture").activeOffsetX([-10,10]).failOffsetY([-15,15]).onStart(()=>{"worklet";C.value=_.value}).onUpdate(n=>{"worklet";const o=C.value+n.translationX;_.value=o>0&&!a||o<0&&!c?0:o>e&&a?e+.35*(o-e):o<-t&&c?.35*(o+t)-t:o}).onEnd(()=>{"worklet";const l=_.value;return a&&l>=n?(_.value=withSpring(i,SPRING_CONFIG),void runOnJS(N)("left")):c&&l<=o?(_.value=withSpring(r,SPRING_CONFIG),void runOnJS(N)("right")):a&&l>=s?(_.value=withSpring(e,SPRING_CONFIG),void runOnJS(j)("left")):c&&l<=-s?(_.value=withSpring(-t,SPRING_CONFIG),void runOnJS(j)("right")):(_.value=withSpring(0,SPRING_CONFIG),void runOnJS(G)())})},[l,C,N,b,y,v,I,G,j,A,x,w,_,p]),T=useAnimatedStyle(()=>({transform:[{translateX:_.value}]})),F=useAnimatedStyle(()=>({opacity:I>0?Math.min(1,Math.max(0,_.value/I)):0})),V=useAnimatedStyle(()=>({opacity:A>0?Math.min(1,Math.max(0,-_.value/A)):0})),E=useMemo(()=>{const e=[];return n?.forEach(t=>{e.push({name:t.key,label:t.label})}),o?.forEach(t=>{e.push({name:t.key,label:t.label})}),e},[n,o]),D=useCallback(e=>{const t=e.nativeEvent.actionName,i=[...n??[],...o??[]].find(e=>e.key===t);i&&(!1!==c&&triggerHaptic("selection"),i.onPress())},[n,o,c]);return y||v?_jsxs(View,{style:[f.root,u],testID:p,accessibilityLabel:h,accessibilityActions:E,onAccessibilityAction:D,children:[y?_jsx(Animated.View,{style:[f.actionsRow,f.actionsLeft,{width:I},m,F],pointerEvents:"box-none",children:n?.map(e=>_jsx(ActionButton,{action:e,theme:S,actionStyles:g,width:w,onPress:k},e.key))}):null,v?_jsx(Animated.View,{style:[f.actionsRow,f.actionsRight,{width:A},m,V],pointerEvents:"box-none",children:o?.map(e=>_jsx(ActionButton,{action:e,theme:S,actionStyles:g,width:w,onPress:k},e.key))}):null,_jsx(GestureDetector,{gesture:P,children:_jsx(Animated.View,{style:[f.content,d,T],children:t})})]}):_jsx(View,{style:u,testID:p,children:t})};Swipeable.displayName="Swipeable";const ActionButton=({action:e,theme:t,actionStyles:n,width:o,onPress:i})=>{warnInvalidValue("Swipeable","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const r=e.tone??"neutral",s=toneToBg(t,r),a=renderSlotIcon(e.icon,{color:toneToOnColor(t,r),size:20,disabled:!1});return _jsxs(Pressable,{onPress:()=>i(e),accessibilityRole:"button",accessibilityLabel:e.label,style:[n.button,{width:o,backgroundColor:s,paddingHorizontal:t.space.sm}],children:[a?_jsx(View,{style:n.icon,children:a}):null,_jsx(Text,{variant:"bodySmall",weight:"semibold",style:[n.label,{color:toneToOnColor(t,r)}],numberOfLines:1,children:e.label})]})},buildActionStyles=e=>StyleSheet.create({button:{flexGrow:0,flexShrink:0,alignItems:"center",justifyContent:"center"},icon:{marginBottom:e.space.xxs},label:{textAlign:"center"}}),buildStyles=e=>StyleSheet.create({root:{position:"relative",overflow:"hidden"},content:{backgroundColor:"transparent"},actionsRow:{position:"absolute",top:0,bottom:0,flexDirection:"row"},actionsLeft:{left:0},actionsRight:{right:0,justifyContent:"flex-end"}});export{Swipeable};export default Swipeable;
|
|
1
|
+
"use strict";import{useCallback,useEffect,useMemo,useRef}from"react";import{Dimensions,Pressable,StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{cancelAnimation,runOnJS,useAnimatedStyle,useSharedValue,withSpring}from"react-native-reanimated";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const SPRING_CONFIG={damping:22,stiffness:260,mass:1},DRAG_ACTIVATION_OFFSET=10,RUBBER_BAND_FACTOR=.35,FAIL_OFFSET_Y=15,ACTION_ICON_SIZE=20,toneToBg=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;default:return e.colors.neutral}},toneToOnColor=(e,t)=>{switch(t){case"primary":return e.colors["on-primary"];case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];default:return e.colors["on-neutral"]}},Swipeable=e=>{const{children:t,leftActions:n,rightActions:o,threshold:i,fullSwipeThreshold:r,onSwipeOpen:s,onSwipeClose:a,disabled:l=!1,haptic:c,containerStyle:u,contentStyle:d,actionStyle:m,accessibilityLabel:h,testID:p}=e,S=useTheme(),w=i??80,b=r??200,f=useMemo(()=>buildStyles(S),[S]),g=useMemo(()=>buildActionStyles(S),[S]),y=!!n&&n.length>0,v=!!o&&o.length>0,x=Dimensions.get("window").width,I=y?w*(n?.length??0):0,A=v?w*(o?.length??0):0,_=useSharedValue(0),C=useSharedValue(0),O=useRef(null);useEffect(()=>()=>{cancelAnimation(_),cancelAnimation(C)},[_,C]);const j=useCallback(e=>{O.current!==e&&(O.current=e,s?.(e))},[s]),G=useCallback(()=>{null!==O.current&&(O.current=null,a?.())},[a]),N=useCallback(e=>{const t="left"===e?n:o,i=t?.[0];i&&(!1!==c&&triggerHaptic("notificationSuccess"),i.onPress(),_.value=withSpring(0,SPRING_CONFIG),O.current=null,a?.())},[n,o,_,a,c]),R=useCallback(()=>{_.value=withSpring(0,SPRING_CONFIG),G()},[_,G]),k=useCallback(e=>{const t=resolveHaptic(c,"selection");t&&triggerHaptic(t),e.onPress(),R()},[R,c]),P=useMemo(()=>{const e=I,t=A,n=b,o=-b,i=x,r=-x,s=w,a=y,c=v;return Gesture.Pan().enabled(!l).withTestId(p?`${p}-gesture`:"swipeable-gesture").activeOffsetX([-10,10]).failOffsetY([-15,15]).onStart(()=>{"worklet";C.value=_.value}).onUpdate(n=>{"worklet";const o=C.value+n.translationX;_.value=o>0&&!a||o<0&&!c?0:o>e&&a?e+.35*(o-e):o<-t&&c?.35*(o+t)-t:o}).onEnd(()=>{"worklet";const l=_.value;return a&&l>=n?(_.value=withSpring(i,SPRING_CONFIG),void runOnJS(N)("left")):c&&l<=o?(_.value=withSpring(r,SPRING_CONFIG),void runOnJS(N)("right")):a&&l>=s?(_.value=withSpring(e,SPRING_CONFIG),void runOnJS(j)("left")):c&&l<=-s?(_.value=withSpring(-t,SPRING_CONFIG),void runOnJS(j)("right")):(_.value=withSpring(0,SPRING_CONFIG),void runOnJS(G)())})},[l,C,N,b,y,v,I,G,j,A,x,w,_,p]),T=useAnimatedStyle(()=>({transform:[{translateX:_.value}]}),[_]),F=useAnimatedStyle(()=>({opacity:I>0?Math.min(1,Math.max(0,_.value/I)):0}),[I,_]),V=useAnimatedStyle(()=>({opacity:A>0?Math.min(1,Math.max(0,-_.value/A)):0}),[A,_]),E=useMemo(()=>{const e=[];return n?.forEach(t=>{e.push({name:t.key,label:t.label})}),o?.forEach(t=>{e.push({name:t.key,label:t.label})}),e},[n,o]),D=useCallback(e=>{const t=e.nativeEvent.actionName,i=[...n??[],...o??[]].find(e=>e.key===t);i&&(!1!==c&&triggerHaptic("selection"),i.onPress())},[n,o,c]);return y||v?_jsxs(View,{style:[f.root,u],testID:p,accessibilityLabel:h,accessibilityActions:E,onAccessibilityAction:D,children:[y?_jsx(Animated.View,{style:[f.actionsRow,f.actionsLeft,{width:I},m,F],pointerEvents:"box-none",children:n?.map(e=>_jsx(ActionButton,{action:e,theme:S,actionStyles:g,width:w,onPress:k},e.key))}):null,v?_jsx(Animated.View,{style:[f.actionsRow,f.actionsRight,{width:A},m,V],pointerEvents:"box-none",children:o?.map(e=>_jsx(ActionButton,{action:e,theme:S,actionStyles:g,width:w,onPress:k},e.key))}):null,_jsx(GestureDetector,{gesture:P,children:_jsx(Animated.View,{style:[f.content,d,T],children:t})})]}):_jsx(View,{style:u,testID:p,children:t})};Swipeable.displayName="Swipeable";const ActionButton=({action:e,theme:t,actionStyles:n,width:o,onPress:i})=>{warnInvalidValue("Swipeable","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const r=e.tone??"neutral",s=toneToBg(t,r),a=renderSlotIcon(e.icon,{color:toneToOnColor(t,r),size:20,disabled:!1});return _jsxs(Pressable,{onPress:()=>i(e),accessibilityRole:"button",accessibilityLabel:e.label,style:[n.button,{width:o,backgroundColor:s,paddingHorizontal:t.space.sm}],children:[a?_jsx(View,{style:n.icon,children:a}):null,_jsx(Text,{variant:"bodySmall",weight:"semibold",style:[n.label,{color:toneToOnColor(t,r)}],numberOfLines:1,children:e.label})]})},buildActionStyles=e=>StyleSheet.create({button:{flexGrow:0,flexShrink:0,alignItems:"center",justifyContent:"center"},icon:{marginBottom:e.space.xxs},label:{textAlign:"center"}}),buildStyles=e=>StyleSheet.create({root:{position:"relative",overflow:"hidden"},content:{backgroundColor:"transparent"},actionsRow:{position:"absolute",top:0,bottom:0,flexDirection:"row"},actionsLeft:{left:0},actionsRight:{right:0,justifyContent:"flex-end"}});export{Swipeable};export default Swipeable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useEffect,useMemo}from"react";import{StyleSheet,View}from"react-native";import Animated,{cancelAnimation,useAnimatedStyle,useSharedValue,withDelay,withRepeat,withSequence,withTiming}from"react-native-reanimated";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_TYPING_INDICATOR_LABELS=Object.freeze({typing:"Typing"});const DOT=6,DIM=.3,PULSE_MS=400,STAGGER_MS=160,STILL_OPACITY=[1,.65,.3],DOT_NAMES=["first","second","third"],Dot=({index:e,still:t,colour:i,dotStyle:s})=>{const o=useSharedValue(.3);useEffect(()=>{if(!t)return o.value=withDelay(160*e,withRepeat(withSequence(withTiming(1,{duration:400}),withTiming(.3,{duration:400})),-1)),()=>cancelAnimation(o)},[t,e,o]);const r=useAnimatedStyle(()=>({opacity:o.value}));return _jsx(Animated.View,{style:[s,{backgroundColor:i},t?{opacity:STILL_OPACITY[e]}:r]})};export const TypingIndicator=({label:e,accessibilityLabel:t,labels:i,bubble:s=!0,style:o,testID:r})=>{const a=useTheme(),l=useMemo(()=>buildStyles(a),[a]),n=useReducedMotion(),c=a.colors["text-subtle"],d=useMemo(()=>({...DEFAULT_TYPING_INDICATOR_LABELS,...i}),[i]);return _jsxs(View,{style:[l.root,s?l.bubble:null,o],accessible:!0,accessibilityRole:"progressbar",accessibilityLabel:e??t??d.typing,accessibilityState:{busy:!0},"aria-busy":!0,testID:r,children:[_jsx(View,{style:l.dots,children:DOT_NAMES.map((e,t)=>_jsx(Dot,{index:t,still:n,colour:c,dotStyle:l.dot},e))}),e?_jsx(Text,{variant:"bodySmall",color:"secondary",children:e}):null]})};const buildStyles=e=>StyleSheet.create({dot:{width:6,height:6,borderRadius:e.radius.pill,...smoothCorners},root:{flexDirection:"row",alignItems:"center",alignSelf:"flex-start",gap:e.space.sm,marginTop:e.space.sm},bubble:{backgroundColor:e.colors["bg-subtle"],borderRadius:e.radius.xl,...smoothCorners,paddingHorizontal:e.space.md,paddingVertical:e.space.sm+e.space.xs},dots:{flexDirection:"row",alignItems:"center",gap:e.space.xs}});export default TypingIndicator;
|
|
1
|
+
"use strict";import{useEffect,useMemo}from"react";import{StyleSheet,View}from"react-native";import Animated,{cancelAnimation,useAnimatedStyle,useSharedValue,withDelay,withRepeat,withSequence,withTiming}from"react-native-reanimated";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_TYPING_INDICATOR_LABELS=Object.freeze({typing:"Typing"});const DOT=6,DIM=.3,PULSE_MS=400,STAGGER_MS=160,STILL_OPACITY=[1,.65,.3],DOT_NAMES=["first","second","third"],Dot=({index:e,still:t,colour:i,dotStyle:s})=>{const o=useSharedValue(.3);useEffect(()=>{if(!t)return o.value=withDelay(160*e,withRepeat(withSequence(withTiming(1,{duration:400}),withTiming(.3,{duration:400})),-1)),()=>cancelAnimation(o)},[t,e,o]);const r=useAnimatedStyle(()=>({opacity:o.value}),[o]);return _jsx(Animated.View,{style:[s,{backgroundColor:i},t?{opacity:STILL_OPACITY[e]}:r]})};export const TypingIndicator=({label:e,accessibilityLabel:t,labels:i,bubble:s=!0,style:o,testID:r})=>{const a=useTheme(),l=useMemo(()=>buildStyles(a),[a]),n=useReducedMotion(),c=a.colors["text-subtle"],d=useMemo(()=>({...DEFAULT_TYPING_INDICATOR_LABELS,...i}),[i]);return _jsxs(View,{style:[l.root,s?l.bubble:null,o],accessible:!0,accessibilityRole:"progressbar",accessibilityLabel:e??t??d.typing,accessibilityState:{busy:!0},"aria-busy":!0,testID:r,children:[_jsx(View,{style:l.dots,children:DOT_NAMES.map((e,t)=>_jsx(Dot,{index:t,still:n,colour:c,dotStyle:l.dot},e))}),e?_jsx(Text,{variant:"bodySmall",color:"secondary",children:e}):null]})};const buildStyles=e=>StyleSheet.create({dot:{width:6,height:6,borderRadius:e.radius.pill,...smoothCorners},root:{flexDirection:"row",alignItems:"center",alignSelf:"flex-start",gap:e.space.sm,marginTop:e.space.sm},bubble:{backgroundColor:e.colors["bg-subtle"],borderRadius:e.radius.xl,...smoothCorners,paddingHorizontal:e.space.md,paddingVertical:e.space.sm+e.space.xs},dots:{flexDirection:"row",alignItems:"center",gap:e.space.xs}});export default TypingIndicator;
|