@fountain-ui/core 2.0.0-beta.10 → 2.0.0-beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/build/commonjs/Accordion/Accordion.js +3 -3
  2. package/build/commonjs/Accordion/Accordion.js.map +1 -1
  3. package/build/commonjs/ButtonBase/ButtonBase.js +56 -52
  4. package/build/commonjs/ButtonBase/ButtonBase.js.map +1 -1
  5. package/build/commonjs/CircularProgress/CircularProgress.js +19 -24
  6. package/build/commonjs/CircularProgress/CircularProgress.js.map +1 -1
  7. package/build/commonjs/ImageCore/ImageCoreNative.js +24 -26
  8. package/build/commonjs/ImageCore/ImageCoreNative.js.map +1 -1
  9. package/build/commonjs/Slide/Slide.js +12 -13
  10. package/build/commonjs/Slide/Slide.js.map +1 -1
  11. package/build/commonjs/Tabs/TabIndicator.js +2 -6
  12. package/build/commonjs/Tabs/TabIndicator.js.map +1 -1
  13. package/build/commonjs/Tabs/Tabs.js +46 -48
  14. package/build/commonjs/Tabs/Tabs.js.map +1 -1
  15. package/build/commonjs/Tabs/useTabCoordinates.js +44 -0
  16. package/build/commonjs/Tabs/useTabCoordinates.js.map +1 -0
  17. package/build/commonjs/Tabs/useTabsWidth.js +26 -0
  18. package/build/commonjs/Tabs/useTabsWidth.js.map +1 -0
  19. package/build/commonjs/Tooltip/Tooltip.js +18 -22
  20. package/build/commonjs/Tooltip/Tooltip.js.map +1 -1
  21. package/build/commonjs/animated/AnimatedPressable.js +2 -3
  22. package/build/commonjs/animated/AnimatedPressable.js.map +1 -1
  23. package/build/commonjs/hooks/useCollapsibleAppBar.js +46 -36
  24. package/build/commonjs/hooks/useCollapsibleAppBar.js.map +1 -1
  25. package/build/commonjs/hooks/useFadeInAppBar.js +35 -18
  26. package/build/commonjs/hooks/useFadeInAppBar.js.map +1 -1
  27. package/build/commonjs/hooks/useThrottle.js +3 -7
  28. package/build/commonjs/hooks/useThrottle.js.map +1 -1
  29. package/build/commonjs/internal/hooks/index.js +0 -8
  30. package/build/commonjs/internal/hooks/index.js.map +1 -1
  31. package/build/commonjs/internal/hooks/useHeight.js +2 -6
  32. package/build/commonjs/internal/hooks/useHeight.js.map +1 -1
  33. package/build/module/Accordion/Accordion.js +3 -3
  34. package/build/module/Accordion/Accordion.js.map +1 -1
  35. package/build/module/ButtonBase/ButtonBase.js +54 -48
  36. package/build/module/ButtonBase/ButtonBase.js.map +1 -1
  37. package/build/module/CircularProgress/CircularProgress.js +20 -21
  38. package/build/module/CircularProgress/CircularProgress.js.map +1 -1
  39. package/build/module/ImageCore/ImageCoreNative.js +20 -23
  40. package/build/module/ImageCore/ImageCoreNative.js.map +1 -1
  41. package/build/module/Slide/Slide.js +14 -10
  42. package/build/module/Slide/Slide.js.map +1 -1
  43. package/build/module/Tabs/TabIndicator.js +3 -7
  44. package/build/module/Tabs/TabIndicator.js.map +1 -1
  45. package/build/module/Tabs/Tabs.js +39 -39
  46. package/build/module/Tabs/Tabs.js.map +1 -1
  47. package/build/module/Tabs/useTabCoordinates.js +30 -0
  48. package/build/module/Tabs/useTabCoordinates.js.map +1 -0
  49. package/build/module/Tabs/useTabsWidth.js +18 -0
  50. package/build/module/Tabs/useTabsWidth.js.map +1 -0
  51. package/build/module/Tooltip/Tooltip.js +15 -15
  52. package/build/module/Tooltip/Tooltip.js.map +1 -1
  53. package/build/module/animated/AnimatedPressable.js +2 -3
  54. package/build/module/animated/AnimatedPressable.js.map +1 -1
  55. package/build/module/hooks/useCollapsibleAppBar.js +46 -34
  56. package/build/module/hooks/useCollapsibleAppBar.js.map +1 -1
  57. package/build/module/hooks/useFadeInAppBar.js +35 -14
  58. package/build/module/hooks/useFadeInAppBar.js.map +1 -1
  59. package/build/module/hooks/useThrottle.js +3 -3
  60. package/build/module/hooks/useThrottle.js.map +1 -1
  61. package/build/module/internal/hooks/index.js +0 -1
  62. package/build/module/internal/hooks/index.js.map +1 -1
  63. package/build/module/internal/hooks/useHeight.js +2 -2
  64. package/build/module/internal/hooks/useHeight.js.map +1 -1
  65. package/build/typescript/Tabs/useTabCoordinates.d.ts +7 -0
  66. package/build/typescript/Tabs/useTabsWidth.d.ts +2 -0
  67. package/build/typescript/animated/AnimatedPressable.d.ts +2 -2
  68. package/build/typescript/internal/hooks/index.d.ts +0 -1
  69. package/package.json +2 -2
  70. package/src/Accordion/Accordion.tsx +5 -3
  71. package/src/ButtonBase/ButtonBase.tsx +65 -43
  72. package/src/CircularProgress/CircularProgress.tsx +24 -30
  73. package/src/ImageCore/ImageCoreNative.tsx +17 -19
  74. package/src/Slide/Slide.tsx +17 -15
  75. package/src/Tabs/TabIndicator.tsx +4 -8
  76. package/src/Tabs/Tabs.tsx +37 -39
  77. package/src/Tabs/useTabCoordinates.ts +36 -0
  78. package/src/Tabs/useTabsWidth.ts +20 -0
  79. package/src/Tooltip/Tooltip.tsx +16 -16
  80. package/src/animated/AnimatedPressable.tsx +1 -2
  81. package/src/hooks/useCollapsibleAppBar.ts +41 -31
  82. package/src/hooks/useFadeInAppBar.ts +31 -15
  83. package/src/hooks/useThrottle.ts +3 -3
  84. package/src/internal/hooks/index.ts +0 -1
  85. package/src/internal/hooks/useHeight.ts +2 -2
  86. package/build/commonjs/ButtonBase/ButtonBase.ios.js +0 -101
  87. package/build/commonjs/ButtonBase/ButtonBase.ios.js.map +0 -1
  88. package/build/commonjs/ButtonBase/useDisabledReaction/index.js +0 -21
  89. package/build/commonjs/ButtonBase/useDisabledReaction/index.js.map +0 -1
  90. package/build/commonjs/ButtonBase/useDisabledReaction/index.native.js +0 -9
  91. package/build/commonjs/ButtonBase/useDisabledReaction/index.native.js.map +0 -1
  92. package/build/commonjs/ImageCore/ImageCoreNative.ios.js +0 -60
  93. package/build/commonjs/ImageCore/ImageCoreNative.ios.js.map +0 -1
  94. package/build/commonjs/internal/hooks/useWidth.js +0 -29
  95. package/build/commonjs/internal/hooks/useWidth.js.map +0 -1
  96. package/build/module/ButtonBase/ButtonBase.ios.js +0 -82
  97. package/build/module/ButtonBase/ButtonBase.ios.js.map +0 -1
  98. package/build/module/ButtonBase/useDisabledReaction/index.js +0 -12
  99. package/build/module/ButtonBase/useDisabledReaction/index.js.map +0 -1
  100. package/build/module/ButtonBase/useDisabledReaction/index.native.js +0 -2
  101. package/build/module/ButtonBase/useDisabledReaction/index.native.js.map +0 -1
  102. package/build/module/ImageCore/ImageCoreNative.ios.js +0 -45
  103. package/build/module/ImageCore/ImageCoreNative.ios.js.map +0 -1
  104. package/build/module/internal/hooks/useWidth.js +0 -15
  105. package/build/module/internal/hooks/useWidth.js.map +0 -1
  106. package/build/typescript/ButtonBase/ButtonBase.ios.d.ts +0 -2
  107. package/build/typescript/ButtonBase/useDisabledReaction/index.d.ts +0 -2
  108. package/build/typescript/ButtonBase/useDisabledReaction/index.native.d.ts +0 -2
  109. package/build/typescript/ImageCore/ImageCoreNative.ios.d.ts +0 -2
  110. package/build/typescript/internal/hooks/useWidth.d.ts +0 -2
  111. package/src/ButtonBase/ButtonBase.ios.tsx +0 -95
  112. package/src/ButtonBase/useDisabledReaction/index.native.ts +0 -4
  113. package/src/ButtonBase/useDisabledReaction/index.ts +0 -16
  114. package/src/ImageCore/ImageCoreNative.ios.tsx +0 -46
  115. package/src/internal/hooks/useWidth.ts +0 -17
@@ -1 +1 @@
1
- {"version":3,"names":["defaultOptions","keyboardDismissMode","ANIMATION_DURATION_MILLIS","SUPPORTS_DRAG_DETECTION","Platform","OS","useCollapsibleAppBar","userOptions","styles","useAppbarStyles","safeAreaInsets","useSafeAreaInsets","appBarHeight","onAppBarLayout","useHeight","collapsibleToolbarHeight","onCollapsibleToolbarLayout","maxTranslateY","useDerivedValue","translateY","useSharedValue","lastTranslateY","lastOffsetY","overlapped","elevationStyle","useElevationStyle","animatedStyle","useAnimatedStyle","transform","value","boxShadow","elevation","shadowColor","shadowOffset","shadowRadius","shadowOpacity","indexRef","React","useRef","offsetsRef","onScrollViewChanged","nextIndex","prevIndex","current","savedOffsetY","withTiming","duration","scrollHandler","useAnimatedScrollHandler","onBeginDrag","runOnJS","Keyboard","dismiss","onMomentumBegin","onScroll","event","offsetY","contentOffset","y","ty","maxTy","dy","Math","min","max","onEndDrag","onMomentumEnd","threshold","nextTranslateY","hasCollapsible","appBarStyle","paddingTop","top","floating","undefined","scrollContentInsets"],"sources":["useCollapsibleAppBar.ts"],"sourcesContent":["import React from 'react';\nimport { Falsy, Keyboard, Platform, RegisteredStyle, ScrollViewProps, ViewProps, ViewStyle } from 'react-native';\nimport {\n runOnJS,\n useAnimatedScrollHandler,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport { useHeight } from '../internal/hooks';\nimport useElevationStyle from './useElevationStyle';\nimport useAppbarStyles from './useAppbarStyles';\n\ntype WebOnlyStyle = { boxShadow: any };\n\ntype ViewStyleProp = Array<ViewStyle | RegisteredStyle<ViewStyle> | WebOnlyStyle | Falsy>;\n\ntype OnScroll = ScrollViewProps['onScroll'];\n\ntype OnLayoutCallback = ViewProps['onLayout'];\n\nexport interface ContentInsets {\n top?: number;\n bottom?: number;\n left?: number;\n right?: number;\n}\n\nexport interface Options {\n keyboardDismissMode?: 'none' | 'on-drag';\n}\n\nexport interface CollapsibleAppBar {\n appBarStyle: ViewStyleProp;\n onAppBarLayout: OnLayoutCallback;\n onCollapsibleToolbarLayout: OnLayoutCallback;\n onScroll: OnScroll;\n onScrollViewChanged: (index: number) => void;\n scrollContentInsets: ContentInsets;\n}\n\nconst defaultOptions: Required<Options> = {\n keyboardDismissMode: 'none',\n};\n\nconst ANIMATION_DURATION_MILLIS = 100;\n\nconst SUPPORTS_DRAG_DETECTION = Platform.OS !== 'web';\n\nexport default function useCollapsibleAppBar(userOptions: Options = defaultOptions): CollapsibleAppBar {\n const { keyboardDismissMode }: Required<Options> = {\n ...defaultOptions,\n ...userOptions,\n };\n\n const styles = useAppbarStyles();\n\n const safeAreaInsets = useSafeAreaInsets();\n\n const [appBarHeight, onAppBarLayout] = useHeight();\n const [collapsibleToolbarHeight, onCollapsibleToolbarLayout] = useHeight();\n\n const maxTranslateY = useDerivedValue(() => -collapsibleToolbarHeight);\n\n const translateY = useSharedValue<number>(0);\n const lastTranslateY = useSharedValue<number>(0);\n const lastOffsetY = useSharedValue<number>(0);\n const overlapped = useSharedValue<boolean>(false);\n\n const elevationStyle = useElevationStyle(4);\n const animatedStyle = useAnimatedStyle(() => {\n return Platform.OS === 'web' ? ({\n transform: [{ translateY: translateY.value }],\n boxShadow: overlapped.value ? elevationStyle?.boxShadow : 0,\n }) : ({\n transform: [{ translateY: translateY.value }],\n elevation: overlapped.value ? elevationStyle?.elevation : 0,\n shadowColor: elevationStyle?.shadowColor,\n shadowOffset: elevationStyle?.shadowOffset,\n shadowRadius: elevationStyle?.shadowRadius,\n shadowOpacity: overlapped.value ? elevationStyle?.shadowOpacity : 0,\n });\n });\n\n const indexRef = React.useRef<number>(0);\n const offsetsRef = React.useRef<Array<number>>([]);\n\n const onScrollViewChanged = (nextIndex: number) => {\n const prevIndex = indexRef.current;\n if (prevIndex === nextIndex) {\n return;\n }\n\n offsetsRef.current[prevIndex] = lastOffsetY.value;\n\n const savedOffsetY = offsetsRef.current[nextIndex] ?? 0;\n lastOffsetY.value = savedOffsetY;\n\n indexRef.current = nextIndex;\n\n // Determine whether to overlap every time index is changed.\n overlapped.value = savedOffsetY > 0;\n\n // If next ScrollView's offset is too short, expand app bar.\n if (translateY.value < 0 && savedOffsetY < appBarHeight) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n };\n\n const scrollHandler = useAnimatedScrollHandler({\n onBeginDrag: () => {\n if (keyboardDismissMode === 'on-drag') {\n runOnJS(Keyboard.dismiss)();\n }\n lastTranslateY.value = translateY.value;\n },\n onMomentumBegin: () => {\n lastTranslateY.value = translateY.value;\n },\n onScroll: (event) => {\n const offsetY = event.contentOffset.y;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n if (SUPPORTS_DRAG_DETECTION) {\n const dy = offsetY - lastOffsetY.value;\n\n translateY.value = offsetY <= 0 ? 0 : Math.min(Math.max(lastTranslateY.value - dy, maxTy), 0);\n\n overlapped.value = offsetY + translateY.value > 0;\n } else {\n if (offsetY > -maxTy) {\n if (ty === 0) {\n translateY.value = withTiming(Math.min(Math.max(-offsetY, maxTy), 0), {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n } else {\n if (ty === maxTy) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n }\n\n overlapped.value = offsetY > 0;\n\n lastOffsetY.value = offsetY;\n }\n },\n onEndDrag: (event) => {\n lastOffsetY.value = event.contentOffset.y;\n },\n onMomentumEnd: (event) => {\n const offsetY = event.contentOffset.y;\n\n lastOffsetY.value = offsetY;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n // If toolbar is already positioned on edge, do nothing.\n if (ty <= maxTy || ty >= 0) {\n return;\n }\n\n const threshold = maxTy * 0.5;\n\n const nextTranslateY = (ty > threshold || offsetY < appBarHeight) ? 0 : maxTy;\n\n overlapped.value = offsetY + nextTranslateY > 0;\n\n translateY.value = withTiming(nextTranslateY, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n },\n });\n\n const hasCollapsible = collapsibleToolbarHeight > 0;\n\n const appBarStyle = [\n animatedStyle,\n { paddingTop: safeAreaInsets.top },\n hasCollapsible ? styles.floating : undefined,\n ];\n\n return {\n appBarStyle,\n onAppBarLayout,\n onCollapsibleToolbarLayout,\n onScroll: scrollHandler,\n onScrollViewChanged,\n scrollContentInsets: { top: hasCollapsible ? appBarHeight : 0 },\n };\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAQA;;AACA;;AACA;;AACA;;;;AA8BA,MAAMA,cAAiC,GAAG;EACtCC,mBAAmB,EAAE;AADiB,CAA1C;AAIA,MAAMC,yBAAyB,GAAG,GAAlC;AAEA,MAA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GhBH,cAAc,GAAG7D,MAAM,CAACiE,QAAV,GAAqBC,SAHnB,CAApB;EAMA,OAAO;IACHJ,WADG;IAEHzD,cAFG;IAGHG,0BAHG;IAIHsC,QAAQ,EAAEP,aAJP;IAKHP,mBALG;IAMHmC,mBAAmB,EAAE;MAAEH,GAAG,EAAEH,cAAc,GAAGzD,YAAH,GAAkB;IAAvC;EANlB,CAAP;AAQH;;AAAA"}
1
+ {"version":3,"names":["defaultOptions","keyboardDismissMode","ANIMATION_CONFIG","duration","SUPPORTS_DRAG_DETECTION","Platform","OS","useCollapsibleAppBar","userOptions","styles","useAppbarStyles","safeAreaInsets","useSafeAreaInsets","appBarHeight","onAppBarLayout","useHeight","collapsibleToolbarHeight","onCollapsibleToolbarLayout","maxTranslateY","useDerivedValue","translateY","useSharedValue","lastTranslateY","lastOffsetY","overlapped","elevationStyle","useElevationStyle","animatedStyle","useAnimatedStyle","transform","value","boxShadow","elevation","shadowColor","shadowOffset","shadowRadius","shadowOpacity","indexRef","useRef","offsetsRef","onScrollViewChanged","nextIndex","prevIndex","current","savedOffsetY","withTiming","scrollHandler","useAnimatedScrollHandler","onBeginDrag","runOnJS","Keyboard","dismiss","onMomentumBegin","onScroll","event","offsetY","contentOffset","y","ty","maxTy","dy","Math","min","max","onEndDrag","onMomentumEnd","threshold","nextTranslateY","hasCollapsible","appBarStyle","paddingTop","top","floating","undefined","scrollContentInsets"],"sources":["useCollapsibleAppBar.ts"],"sourcesContent":["import { useRef } from 'react';\nimport { Falsy, Keyboard, Platform, RegisteredStyle, ScrollViewProps, ViewProps, ViewStyle } from 'react-native';\nimport type { WithTimingConfig } from 'react-native-reanimated';\nimport {\n runOnJS,\n useAnimatedScrollHandler,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport { useHeight } from '../internal/hooks';\nimport useElevationStyle from './useElevationStyle';\nimport useAppbarStyles from './useAppbarStyles';\n\ntype WebOnlyStyle = { boxShadow: any };\n\ntype ViewStyleProp = Array<ViewStyle | RegisteredStyle<ViewStyle> | WebOnlyStyle | Falsy>;\n\ntype OnScroll = ScrollViewProps['onScroll'];\n\ntype OnLayoutCallback = ViewProps['onLayout'];\n\nexport interface ContentInsets {\n top?: number;\n bottom?: number;\n left?: number;\n right?: number;\n}\n\nexport interface Options {\n keyboardDismissMode?: 'none' | 'on-drag';\n}\n\nexport interface CollapsibleAppBar {\n appBarStyle: ViewStyleProp;\n onAppBarLayout: OnLayoutCallback;\n onCollapsibleToolbarLayout: OnLayoutCallback;\n onScroll: OnScroll;\n onScrollViewChanged: (index: number) => void;\n scrollContentInsets: ContentInsets;\n}\n\nconst defaultOptions: Required<Options> = {\n keyboardDismissMode: 'none',\n};\n\nconst ANIMATION_CONFIG: Readonly<WithTimingConfig> = { duration: 100 };\n\nconst SUPPORTS_DRAG_DETECTION = Platform.OS !== 'web';\n\nexport default function useCollapsibleAppBar(userOptions: Options = defaultOptions): CollapsibleAppBar {\n const { keyboardDismissMode }: Required<Options> = {\n ...defaultOptions,\n ...userOptions,\n };\n\n const styles = useAppbarStyles();\n\n const safeAreaInsets = useSafeAreaInsets();\n\n const [appBarHeight, onAppBarLayout] = useHeight();\n const [collapsibleToolbarHeight, onCollapsibleToolbarLayout] = useHeight();\n\n const maxTranslateY = useDerivedValue(() => -collapsibleToolbarHeight, [collapsibleToolbarHeight]);\n\n const translateY = useSharedValue<number>(0);\n const lastTranslateY = useSharedValue<number>(0);\n const lastOffsetY = useSharedValue<number>(0);\n const overlapped = useSharedValue<boolean>(false);\n\n const elevationStyle = useElevationStyle(4);\n const animatedStyle = useAnimatedStyle(() => {\n const transform = [{ translateY: translateY.value }];\n\n if (Platform.OS === 'web') {\n return {\n transform,\n boxShadow: overlapped.value ? elevationStyle?.boxShadow : 0,\n };\n }\n if (Platform.OS === 'android') {\n return {\n transform,\n elevation: overlapped.value ? elevationStyle?.elevation : 0,\n };\n }\n if (Platform.OS === 'ios') {\n return {\n transform,\n shadowColor: elevationStyle?.shadowColor,\n shadowOffset: elevationStyle?.shadowOffset,\n shadowRadius: elevationStyle?.shadowRadius,\n shadowOpacity: overlapped.value ? elevationStyle?.shadowOpacity : 0,\n };\n }\n return {};\n }, [\n /**\n * FIXME: Consider add `elevationStyle` to dependencies.\n */\n ]);\n\n const indexRef = useRef<number>(0);\n const offsetsRef = useRef<Array<number>>([]);\n\n const onScrollViewChanged = (nextIndex: number) => {\n const prevIndex = indexRef.current;\n if (prevIndex === nextIndex) {\n return;\n }\n\n offsetsRef.current[prevIndex] = lastOffsetY.value;\n\n const savedOffsetY = offsetsRef.current[nextIndex] ?? 0;\n lastOffsetY.value = savedOffsetY;\n\n indexRef.current = nextIndex;\n\n // Determine whether to overlap every time index is changed.\n overlapped.value = savedOffsetY > 0;\n\n // If next ScrollView's offset is too short, expand app bar.\n if (translateY.value < 0 && savedOffsetY < appBarHeight) {\n translateY.value = withTiming(0, ANIMATION_CONFIG);\n }\n };\n\n const scrollHandler = useAnimatedScrollHandler({\n onBeginDrag: () => {\n if (keyboardDismissMode === 'on-drag') {\n runOnJS(Keyboard.dismiss)();\n }\n lastTranslateY.value = translateY.value;\n },\n onMomentumBegin: () => {\n lastTranslateY.value = translateY.value;\n },\n onScroll: (event) => {\n const offsetY = event.contentOffset.y;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n if (SUPPORTS_DRAG_DETECTION) {\n const dy = offsetY - lastOffsetY.value;\n\n translateY.value = offsetY <= 0 ? 0 : Math.min(Math.max(lastTranslateY.value - dy, maxTy), 0);\n\n overlapped.value = offsetY + translateY.value > 0;\n } else {\n if (offsetY > -maxTy) {\n if (ty === 0) {\n translateY.value = withTiming(Math.min(Math.max(-offsetY, maxTy), 0), ANIMATION_CONFIG);\n }\n } else {\n if (ty === maxTy) {\n translateY.value = withTiming(0, ANIMATION_CONFIG);\n }\n }\n\n overlapped.value = offsetY > 0;\n\n lastOffsetY.value = offsetY;\n }\n },\n onEndDrag: (event) => {\n lastOffsetY.value = event.contentOffset.y;\n },\n onMomentumEnd: (event) => {\n const offsetY = event.contentOffset.y;\n\n lastOffsetY.value = offsetY;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n // If toolbar is already positioned on edge, do nothing.\n if (ty <= maxTy || ty >= 0) {\n return;\n }\n\n const threshold = maxTy * 0.5;\n\n const nextTranslateY = (ty > threshold || offsetY < appBarHeight) ? 0 : maxTy;\n\n overlapped.value = offsetY + nextTranslateY > 0;\n\n translateY.value = withTiming(nextTranslateY, ANIMATION_CONFIG);\n },\n }, [keyboardDismissMode]);\n\n const hasCollapsible = collapsibleToolbarHeight > 0;\n\n const appBarStyle = [\n animatedStyle,\n { paddingTop: safeAreaInsets.top },\n hasCollapsible ? styles.floating : undefined,\n ];\n\n return {\n appBarStyle,\n onAppBarLayout,\n onCollapsibleToolbarLayout,\n onScroll: scrollHandler,\n onScrollViewChanged,\n scrollContentInsets: { top: hasCollapsible ? appBarHeight : 0 },\n };\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AAQA;;AACA;;AACA;;AACA;;;;AA8BA,MAAMA,cAAiC,GAAG;EACtCC,mBAAmB,EAAE;AADiB,CAA1C;AAIA,MAAMC,gBAA4C,GAAG;EAAEC,QAAQ,EAAE;AAAZ,CAArD;AAEA,MAAMC,uBAAuB,GAAGC,qBAAA,CAASC,EAAT,KAAgB,KAAhD;;AAEe,SAASC,oBAAT,GAAwF;EAAA,IAA1DC,WAA0D,uEAAnCR,cAAmC;EACnG,MAAM;IAAEC;EAAF,IAA6C,EAC/C,GAAGD,cAD4C;IAE/C,GAAGQ;EAF4C,CAAnD;EAKA,MAAMC,MAAM,GAAG,IAAAC,wBAAA,GAAf;EAEA,MAAMC,cAAc,GAAG,IAAAC,6CAAA,GAAvB;EAEA,MAAM,CAACC,YAAD,EAAeC,cAAf,IAAiC,IAAAC,gBAAA,GAAvC;EACA,MAAM,CAACC,wBAAD,EAA2B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defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = useFadeInAppBar;
7
7
 
8
- var _react = _interopRequireDefault(require("react"));
8
+ var _react = require("react");
9
9
 
10
10
  var _reactNative = require("react-native");
11
11
 
@@ -48,31 +48,48 @@ function useFadeInAppBar() {
48
48
  const styles = (0, _useAppbarStyles.default)();
49
49
  const safeAreaInsets = (0, _reactNativeSafeAreaContext.useSafeAreaInsets)();
50
50
  const [appBarHeight, onAppBarLayout] = (0, _hooks.useHeight)();
51
-
52
- const [fromOffsetY, toOffsetY] = _react.default.useMemo(() => {
51
+ const [fromOffsetY, toOffsetY] = (0, _react.useMemo)(() => {
53
52
  const endY = typeof fadeInEndY === 'function' ? fadeInEndY(appBarHeight) : fadeInEndY;
54
53
  const beginY = typeof fadeInBeginY === 'function' ? fadeInBeginY(endY, appBarHeight) : fadeInBeginY;
55
54
  return [beginY, endY];
56
55
  }, [fadeInBeginY, fadeInBeginY, appBarHeight]);
57
-
58
56
  const dy = (0, _reactNativeReanimated.useSharedValue)(0);
59
57
  const lastOffsetY = (0, _reactNativeReanimated.useSharedValue)(0);
60
58
  const normalized = (0, _reactNativeReanimated.useSharedValue)(0);
61
- const backgroundColor = theme.palette.background.default;
62
-
63
- const [r, g, b] = _react.default.useMemo(() => (0, _utils.rgb)(backgroundColor), [backgroundColor]);
64
-
65
- const animatedAppBarStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
66
- backgroundColor: `rgba(${r}, ${g}, ${b}, ${normalized.value})`,
67
- elevation: normalized.value >= 1 ? 6 : 0,
68
- shadowColor: '#000',
69
- shadowOffset,
70
- shadowRadius: 4.65,
71
- shadowOpacity: normalized.value >= 1 ? 0.25 : 0
72
- }));
59
+ const originalBackgroundColor = theme.palette.background.default;
60
+ const rgbValues = (0, _react.useMemo)(() => (0, _utils.rgb)(originalBackgroundColor), [originalBackgroundColor]);
61
+ const animatedAppBarStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
62
+ const [r, g, b] = rgbValues;
63
+ const backgroundColor = `rgba(${r}, ${g}, ${b}, ${normalized.value})`;
64
+
65
+ if (_reactNative.Platform.OS === 'web') {
66
+ return {
67
+ backgroundColor
68
+ };
69
+ }
70
+
71
+ if (_reactNative.Platform.OS === 'android') {
72
+ return {
73
+ backgroundColor,
74
+ elevation: normalized.value >= 1 ? 6 : 0
75
+ };
76
+ }
77
+
78
+ if (_reactNative.Platform.OS === 'ios') {
79
+ return {
80
+ backgroundColor,
81
+ shadowColor: '#000',
82
+ shadowOffset,
83
+ shadowRadius: 4.65,
84
+ shadowOpacity: normalized.value >= 1 ? 0.25 : 0
85
+ };
86
+ }
87
+
88
+ return {};
89
+ }, [rgbValues]);
73
90
  const animatedTitleStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
74
91
  opacity: normalized.value
75
- }));
92
+ }), []);
76
93
  const scrollHandler = (0, _reactNativeReanimated.useAnimatedScrollHandler)({
77
94
  onBeginDrag: () => {
78
95
  if (keyboardDismissMode === 'on-drag') {
@@ -92,7 +109,7 @@ function useFadeInAppBar() {
92
109
  onMomentumEnd: event => {
93
110
  lastOffsetY.value = event.contentOffset.y;
94
111
  }
95
- });
112
+ }, [keyboardDismissMode]);
96
113
  const appBarStyle = [animatedAppBarStyle, {
97
114
  paddingTop: safeAreaInsets.top
98
115
  }, floating ? styles.floating : undefined];
@@ -1 +1 @@
1
- {"version":3,"names":["defaultOptions","fadeInBeginY","endY","appBarHeight","fadeInEndY","floating","keyboardDismissMode","shadowOffset","Platform","OS","width","height","undefined","useFadeInAppBar","userOptions","theme","useTheme","styles","useAppbarStyles","safeAreaInsets","useSafeAreaInsets","onAppBarLayout","useHeight","fromOffsetY","toOffsetY","React","useMemo","beginY","dy","useSharedValue","lastOffsetY","normalized","backgroundColor","palette","background","default","r","g","b","rgb","animatedAppBarStyle","useAnimatedStyle","value","elevation","shadowColor","shadowRadius","shadowOpacity","animatedTitleStyle","opacity","scrollHandler","useAnimatedScrollHandler","onBeginDrag","runOnJS","Keyboard","dismiss","onScroll","event","offsetY","contentOffset","y","distance","Math","max","localOffsetY","min","onEndDrag","onMomentumEnd","appBarStyle","paddingTop","top","titleStyle"],"sources":["useFadeInAppBar.ts"],"sourcesContent":["import React from 'react';\nimport { Falsy, Keyboard, Platform, RegisteredStyle, ScrollViewProps, ViewProps, ViewStyle } from 'react-native';\nimport type { SharedValue } from 'react-native-reanimated';\nimport { runOnJS, useAnimatedScrollHandler, useAnimatedStyle, useSharedValue } from 'react-native-reanimated';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport { rgb } from '@fountain-ui/utils';\nimport { useHeight } from '../internal/hooks';\nimport { useTheme } from '../styles';\nimport useAppbarStyles from './useAppbarStyles';\n\ntype ViewStyleProp = Array<ViewStyle | RegisteredStyle<ViewStyle> | Falsy>;\n\ntype OnScroll = ScrollViewProps['onScroll'];\n\ntype OnLayoutCallback = ViewProps['onLayout'];\n\nexport interface Options {\n fadeInBeginY?: number | ((endY: number, appBarHeight: number) => number);\n fadeInEndY?: number | ((appBarHeight: number) => number);\n floating?: boolean;\n keyboardDismissMode?: 'none' | 'on-drag';\n}\n\nexport interface FadeInAppBar {\n appBarStyle: ViewStyleProp;\n titleStyle: ViewStyleProp;\n onAppBarLayout: OnLayoutCallback;\n onScroll: OnScroll;\n dy: SharedValue<number>;\n normalized: SharedValue<number>;\n}\n\nconst defaultOptions: Required<Options> = {\n fadeInBeginY: (endY, appBarHeight) => endY - appBarHeight,\n fadeInEndY: (appBarHeight) => appBarHeight,\n floating: true,\n keyboardDismissMode: 'none',\n};\n\nconst shadowOffset = Platform.OS === 'ios' ? { width: 0, height: 3 } : undefined;\n\nexport default function useFadeInAppBar(userOptions: Options = defaultOptions): FadeInAppBar {\n const {\n fadeInBeginY,\n fadeInEndY,\n floating,\n keyboardDismissMode,\n }: Required<Options> = {\n ...defaultOptions,\n ...userOptions,\n };\n\n const theme = useTheme();\n\n const styles = useAppbarStyles();\n\n const safeAreaInsets = useSafeAreaInsets();\n\n const [appBarHeight, onAppBarLayout] = useHeight();\n\n const [fromOffsetY, toOffsetY] = React.useMemo(() => {\n const endY = typeof fadeInEndY === 'function'\n ? fadeInEndY(appBarHeight)\n : fadeInEndY;\n\n const beginY = typeof fadeInBeginY === 'function'\n ? fadeInBeginY(endY, appBarHeight)\n : fadeInBeginY;\n\n return [beginY, endY];\n }, [fadeInBeginY, fadeInBeginY, appBarHeight]);\n\n const dy = useSharedValue<number>(0);\n const lastOffsetY = useSharedValue<number>(0);\n const normalized = useSharedValue<number>(0);\n\n const backgroundColor = theme.palette.background.default;\n const [r, g, b] = React.useMemo(() => rgb(backgroundColor), [backgroundColor]);\n\n const animatedAppBarStyle = useAnimatedStyle(() => ({\n backgroundColor: `rgba(${r}, ${g}, ${b}, ${normalized.value})`,\n elevation: normalized.value >= 1 ? 6 : 0,\n shadowColor: '#000',\n shadowOffset,\n shadowRadius: 4.65,\n shadowOpacity: normalized.value >= 1 ? 0.25 : 0,\n }));\n\n const animatedTitleStyle = useAnimatedStyle(() => ({\n opacity: normalized.value,\n }));\n\n const scrollHandler = useAnimatedScrollHandler({\n onBeginDrag: () => {\n if (keyboardDismissMode === 'on-drag') {\n runOnJS(Keyboard.dismiss)();\n }\n },\n onScroll: (event) => {\n const offsetY = event.contentOffset.y;\n\n const distance = Math.max(toOffsetY - fromOffsetY, 1);\n const localOffsetY = offsetY - fromOffsetY;\n\n dy.value = offsetY - lastOffsetY.value;\n\n normalized.value = Math.min(Math.max(localOffsetY / distance, 0), 1);\n },\n onEndDrag: (event) => {\n lastOffsetY.value = event.contentOffset.y;\n },\n onMomentumEnd: (event) => {\n lastOffsetY.value = event.contentOffset.y;\n },\n });\n\n const appBarStyle = [\n animatedAppBarStyle,\n { paddingTop: safeAreaInsets.top },\n floating ? styles.floating : undefined,\n ];\n\n return {\n appBarStyle,\n titleStyle: [animatedTitleStyle],\n onAppBarLayout,\n onScroll: scrollHandler,\n dy,\n normalized,\n };\n};\n"],"mappings":";;;;;;;AAA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WAArB,EAAkC,CAAlC,CAAjB;MACA,MAAMwC,YAAY,GAAGN,OAAO,GAAGlC,WAA/B;MAEAK,EAAE,CAACc,KAAH,GAAWe,OAAO,GAAG3B,WAAW,CAACY,KAAjC;MAEAX,UAAU,CAACW,KAAX,GAAmBmB,IAAI,CAACG,GAAL,CAASH,IAAI,CAACC,GAAL,CAASC,YAAY,GAAGH,QAAxB,EAAkC,CAAlC,CAAT,EAA+C,CAA/C,CAAnB;IACH,CAf0C;IAgB3CK,SAAS,EAAGT,KAAD,IAAW;MAClB1B,WAAW,CAACY,KAAZ,GAAoBc,KAAK,CAACE,aAAN,CAAoBC,CAAxC;IACH,CAlB0C;IAmB3CO,aAAa,EAAGV,KAAD,IAAW;MACtB1B,WAAW,CAACY,KAAZ,GAAoBc,KAAK,CAACE,aAAN,CAAoBC,CAAxC;IACH;EArB0C,CAAzB,CAAtB;EAwBA,MAAMQ,WAAW,GAAG,CAChB3B,mBADgB,EAEhB;IAAE4B,UAAU,EAAEjD,cAAc,CAACkD;EAA7B,CAFgB,EAGhBhE,QAAQ,GAAGY,MAAM,CAACZ,QAAV,GAAqBO,SAHb,CAApB;EAMA,OAAO;IACHuD,WADG;IAEHG,UAAU,EAAE,CAACvB,kBAAD,CAFT;IAGH1B,cAHG;IAIHkC,QAAQ,EAAEN,aAJP;IAKHrB,EALG;IAMHG;EANG,CAAP;AAQH;;AAAA"}
1
+ {"version":3,"names":["defaultOptions","fadeInBeginY","endY","appBarHeight","fadeInEndY","floating","keyboardDismissMode","shadowOffset","Platform","OS","width","height","undefined","useFadeInAppBar","userOptions","theme","useTheme","styles","useAppbarStyles","safeAreaInsets","useSafeAreaInsets","onAppBarLayout","useHeight","fromOffsetY","toOffsetY","useMemo","beginY","dy","useSharedValue","lastOffsetY","normalized","originalBackgroundColor","palette","background","default","rgbValues","rgb","animatedAppBarStyle","useAnimatedStyle","r","g","b","backgroundColor","value","elevation","shadowColor","shadowRadius","shadowOpacity","animatedTitleStyle","opacity","scrollHandler","useAnimatedScrollHandler","onBeginDrag","runOnJS","Keyboard","dismiss","onScroll","event","offsetY","contentOffset","y","distance","Math","max","localOffsetY","min","onEndDrag","onMomentumEnd","appBarStyle","paddingTop","top","titleStyle"],"sources":["useFadeInAppBar.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { Falsy, Keyboard, Platform, RegisteredStyle, ScrollViewProps, ViewProps, ViewStyle } from 'react-native';\nimport type { SharedValue } from 'react-native-reanimated';\nimport { runOnJS, useAnimatedScrollHandler, useAnimatedStyle, useSharedValue } from 'react-native-reanimated';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport { rgb } from '@fountain-ui/utils';\nimport { useHeight } from '../internal/hooks';\nimport { useTheme } from '../styles';\nimport useAppbarStyles from './useAppbarStyles';\n\ntype ViewStyleProp = Array<ViewStyle | RegisteredStyle<ViewStyle> | Falsy>;\n\ntype OnScroll = ScrollViewProps['onScroll'];\n\ntype OnLayoutCallback = ViewProps['onLayout'];\n\nexport interface Options {\n fadeInBeginY?: number | ((endY: number, appBarHeight: number) => number);\n fadeInEndY?: number | ((appBarHeight: number) => number);\n floating?: boolean;\n keyboardDismissMode?: 'none' | 'on-drag';\n}\n\nexport interface FadeInAppBar {\n appBarStyle: ViewStyleProp;\n titleStyle: ViewStyleProp;\n onAppBarLayout: OnLayoutCallback;\n onScroll: OnScroll;\n dy: SharedValue<number>;\n normalized: SharedValue<number>;\n}\n\nconst defaultOptions: Required<Options> = {\n fadeInBeginY: (endY, appBarHeight) => endY - appBarHeight,\n fadeInEndY: (appBarHeight) => appBarHeight,\n floating: true,\n keyboardDismissMode: 'none',\n};\n\nconst shadowOffset = Platform.OS === 'ios' ? { width: 0, height: 3 } : undefined;\n\nexport default function useFadeInAppBar(userOptions: Options = defaultOptions): FadeInAppBar {\n const {\n fadeInBeginY,\n fadeInEndY,\n floating,\n keyboardDismissMode,\n }: Required<Options> = {\n ...defaultOptions,\n ...userOptions,\n };\n\n const theme = useTheme();\n\n const styles = useAppbarStyles();\n\n const safeAreaInsets = useSafeAreaInsets();\n\n const [appBarHeight, onAppBarLayout] = useHeight();\n\n const [fromOffsetY, toOffsetY] = useMemo(() => {\n const endY = typeof fadeInEndY === 'function'\n ? fadeInEndY(appBarHeight)\n : fadeInEndY;\n\n const beginY = typeof fadeInBeginY === 'function'\n ? fadeInBeginY(endY, appBarHeight)\n : fadeInBeginY;\n\n return [beginY, endY];\n }, [fadeInBeginY, fadeInBeginY, appBarHeight]);\n\n const dy = useSharedValue<number>(0);\n const lastOffsetY = useSharedValue<number>(0);\n const normalized = useSharedValue<number>(0);\n\n const originalBackgroundColor = theme.palette.background.default;\n const rgbValues = useMemo(() => rgb(originalBackgroundColor), [originalBackgroundColor]);\n\n const animatedAppBarStyle = useAnimatedStyle(() => {\n const [r, g, b] = rgbValues;\n const backgroundColor = `rgba(${r}, ${g}, ${b}, ${normalized.value})`;\n\n if (Platform.OS === 'web') {\n return { backgroundColor };\n }\n if (Platform.OS === 'android') {\n return {\n backgroundColor,\n elevation: normalized.value >= 1 ? 6 : 0,\n };\n }\n if (Platform.OS === 'ios') {\n return {\n backgroundColor,\n shadowColor: '#000',\n shadowOffset,\n shadowRadius: 4.65,\n shadowOpacity: normalized.value >= 1 ? 0.25 : 0,\n };\n }\n return {};\n }, [rgbValues]);\n\n const animatedTitleStyle = useAnimatedStyle(() => ({\n opacity: normalized.value,\n }), []);\n\n const scrollHandler = useAnimatedScrollHandler({\n onBeginDrag: () => {\n if (keyboardDismissMode === 'on-drag') {\n runOnJS(Keyboard.dismiss)();\n }\n },\n onScroll: (event) => {\n const offsetY = event.contentOffset.y;\n\n const distance = Math.max(toOffsetY - fromOffsetY, 1);\n const localOffsetY = offsetY - fromOffsetY;\n\n dy.value = offsetY - lastOffsetY.value;\n\n normalized.value = Math.min(Math.max(localOffsetY / distance, 0), 1);\n },\n onEndDrag: (event) => {\n lastOffsetY.value = event.contentOffset.y;\n },\n onMomentumEnd: (event) => {\n lastOffsetY.value = event.contentOffset.y;\n },\n }, [keyboardDismissMode]);\n\n const appBarStyle = [\n animatedAppBarStyle,\n { paddingTop: safeAreaInsets.top },\n floating ? styles.floating : undefined,\n ];\n\n return {\n appBarStyle,\n titleStyle: [animatedTitleStyle],\n onAppBarLayout,\n onScroll: scrollHandler,\n dy,\n normalized,\n };\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAwBA,MAAMA,cAAiC,GAAG;EACtCC,YAAY,EAAE,CAACC,IAAD,EAAOC,YAAP,KAAwBD,IAAI,GAAGC,YADP;EAEtCC,UAAU,EAAGD,YAAD,IAAkBA,YAFQ;EAGtCE,QAAQ,EAAE,IAH4B;EAItCC,mBAAmB,EAAE;AAJiB,CAA1C;AAOA,MAAMC,YAAY,GAAGC,qBAAA,CAASC,EAAT,KAAgB,KAAhB,GAAwB;EAAEC,KAAK,EAAE,CAAT;EAAYC,MAAM,EAAE;AAApB,CAAxB,GAAkDC,SAAvE;;AAEe,SAASC,eAAT,GAA8E;EAAA,IAArDC,WAAqD,uEAA9Bd,cAA8B;EACzF,MAAM;IACFC,YADE;IAEFG,UAFE;IAGFC,QAHE;IAIFC;EAJE,IAKiB,EACnB,GAAGN,cADgB;IAEnB,GAAGc;EAFgB,CALvB;EAUA,MAAMC,KAAK,GAAG,IAAAC,gBAAA,GAAd;EAEA,MAAMC,MAAM,GAAG,IAAAC,wBAAA,GAAf;EAEA,MAAMC,cAAc,GAAG,IAAAC,6CAAA,GAAvB;EAEA,MAAM,CAACjB,YAAD,EAAekB,cAAf,IAAiC,IAAAC,gBAAA,GAAvC;EAEA,MAAM,CAACC,WAAD,EAAcC,SAAd,IAA2B,IAAAC,cAAA,EAAQ,MAAM;IAC3C,MAAMvB,IAAI,GAAG,OAAOE,UAAP,KAAsB,UAAtB,GACPA,UAAU,CAACD,YAAD,CADH,GAEPC,UAFN;IAIA,MAAMsB,MAAM,GAAG,OAAOzB,YAAP,KAAwB,UAAxB,GAC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cAAc,CAACmD;EAA7B,CAFgB,EAGhBjE,QAAQ,GAAGY,MAAM,CAACZ,QAAV,GAAqBO,SAHb,CAApB;EAMA,OAAO;IACHwD,WADG;IAEHG,UAAU,EAAE,CAACvB,kBAAD,CAFT;IAGH3B,cAHG;IAIHmC,QAAQ,EAAEN,aAJP;IAKHvB,EALG;IAMHG;EANG,CAAP;AAQH;;AAAA"}
@@ -5,19 +5,15 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = useThrottle;
7
7
 
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+ var _react = require("react");
11
9
 
12
10
  function useThrottle(options) {
13
11
  const {
14
12
  periodMillis,
15
13
  callback
16
14
  } = options;
17
-
18
- const lastExecMillisRef = _react.default.useRef(0);
19
-
20
- return _react.default.useCallback(function () {
15
+ const lastExecMillisRef = (0, _react.useRef)(0);
16
+ return (0, _react.useCallback)(function () {
21
17
  const now = Date.now();
22
18
  const millisAfterExecuted = now - lastExecMillisRef.current;
23
19
  lastExecMillisRef.current = now;
@@ -1 +1 @@
1
- {"version":3,"names":["useThrottle","options","periodMillis","callback","lastExecMillisRef","React","useRef","useCallback","now","Date","millisAfterExecuted","current"],"sources":["useThrottle.ts"],"sourcesContent":["import React from 'react';\n\nexport interface ThrottleOptions {\n periodMillis: number;\n callback?: (args?: any) => void;\n}\n\nexport default function useThrottle(options: ThrottleOptions) {\n const { periodMillis, callback } = options;\n\n const lastExecMillisRef = React.useRef(0);\n\n return React.useCallback((...args: any[]) => {\n const now = Date.now();\n const millisAfterExecuted = now - lastExecMillisRef.current;\n lastExecMillisRef.current = now;\n\n if (millisAfterExecuted > periodMillis || periodMillis <= 0) {\n if (callback) {\n callback(...args);\n }\n }\n }, [callback, periodMillis]);\n}\n"],"mappings":";;;;;;;AAAA;;;;AAOe,SAASA,WAAT,CAAqBC,OAArB,EAA+C;EAC1D,MAAM;IAAEC,YAAF;IAAgBC;EAAhB,IAA6BF,OAAnC;;EAEA,MAAMG,iBAAiB,GAAGC,cAAA,CAAMC,MAAN,CAAa,CAAb,CAA1B;;EAEA,OAAOD,cAAA,CAAME,WAAN,CAAkB,YAAoB;IACzC,MAAMC,GAAG,GAAGC,IAAI,CAACD,GAAL,EAAZ;IACA,MAAME,mBAAmB,GAAGF,GAAG,GAAGJ,iBAAiB,CAACO,OAApD;IACAP,iBAAiB,CAACO,OAAlB,GAA4BH,GAA5B;;IAEA,IAAIE,mBAAmB,GAAGR,YAAtB,IAAsCA,YAAY,IAAI,CAA1D,EAA6D;MACzD,IAAIC,QAAJ,EAAc;QACVA,QAAQ,CAAC,YAAD,CAAR;MACH;IACJ;EACJ,CAVM,EAUJ,CAACA,QAAD,EAAWD,YAAX,CAVI,CAAP;AAWH"}
1
+ {"version":3,"names":["useThrottle","options","periodMillis","callback","lastExecMillisRef","useRef","useCallback","now","Date","millisAfterExecuted","current"],"sources":["useThrottle.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\n\nexport interface ThrottleOptions {\n periodMillis: number;\n callback?: (args?: any) => void;\n}\n\nexport default function useThrottle(options: ThrottleOptions) {\n const { periodMillis, callback } = options;\n\n const lastExecMillisRef = useRef(0);\n\n return useCallback((...args: any[]) => {\n const now = Date.now();\n const millisAfterExecuted = now - lastExecMillisRef.current;\n lastExecMillisRef.current = now;\n\n if (millisAfterExecuted > periodMillis || periodMillis <= 0) {\n if (callback) {\n callback(...args);\n }\n }\n }, [callback, periodMillis]);\n}\n"],"mappings":";;;;;;;AAAA;;AAOe,SAASA,WAAT,CAAqBC,OAArB,EAA+C;EAC1D,MAAM;IAAEC,YAAF;IAAgBC;EAAhB,IAA6BF,OAAnC;EAEA,MAAMG,iBAAiB,GAAG,IAAAC,aAAA,EAAO,CAAP,CAA1B;EAEA,OAAO,IAAAC,kBAAA,EAAY,YAAoB;IACnC,MAAMC,GAAG,GAAGC,IAAI,CAACD,GAAL,EAAZ;IACA,MAAME,mBAAmB,GAAGF,GAAG,GAAGH,iBAAiB,CAACM,OAApD;IACAN,iBAAiB,CAACM,OAAlB,GAA4BH,GAA5B;;IAEA,IAAIE,mBAAmB,GAAGP,YAAtB,IAAsCA,YAAY,IAAI,CAA1D,EAA6D;MACzD,IAAIC,QAAJ,EAAc;QACVA,QAAQ,CAAC,YAAD,CAAR;MACH;IACJ;EACJ,CAVM,EAUJ,CAACA,QAAD,EAAWD,YAAX,CAVI,CAAP;AAWH"}
@@ -9,16 +9,8 @@ Object.defineProperty(exports, "useHeight", {
9
9
  return _useHeight.default;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "useWidth", {
13
- enumerable: true,
14
- get: function () {
15
- return _useWidth.default;
16
- }
17
- });
18
12
 
19
13
  var _useHeight = _interopRequireDefault(require("./useHeight"));
20
14
 
21
- var _useWidth = _interopRequireDefault(require("./useWidth"));
22
-
23
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
16
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default as useHeight } from './useHeight';\nexport { default as useWidth } from './useWidth';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AACA"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default as useHeight } from './useHeight';\n"],"mappings":";;;;;;;;;;;;AAAA"}
@@ -5,17 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = useHeight;
7
7
 
8
- var _react = _interopRequireDefault(require("react"));
8
+ var _react = require("react");
9
9
 
10
10
  var _reactNativeReanimated = require("react-native-reanimated");
11
11
 
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
12
  function useHeight() {
15
13
  let initialHeight = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
16
-
17
- const [height, setHeight] = _react.default.useState(initialHeight);
18
-
14
+ const [height, setHeight] = (0, _react.useState)(initialHeight);
19
15
  const onLayout = (0, _reactNativeReanimated.useWorkletCallback)(e => {
20
16
  setHeight(e.nativeEvent.layout.height);
21
17
  }, []);
@@ -1 +1 @@
1
- {"version":3,"names":["useHeight","initialHeight","height","setHeight","React","useState","onLayout","useWorkletCallback","e","nativeEvent","layout"],"sources":["useHeight.ts"],"sourcesContent":["import React from 'react';\nimport { ViewProps } from 'react-native';\nimport { useWorkletCallback } from 'react-native-reanimated';\n\ntype OnLayoutCallback = ViewProps['onLayout'];\n\nexport default function useHeight(initialHeight = 0): [number, OnLayoutCallback] {\n const [height, setHeight] = React.useState<number>(initialHeight);\n\n const onLayout = useWorkletCallback((e) => {\n setHeight(e.nativeEvent.layout.height);\n }, []);\n\n return [height, onLayout];\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;;;AAIe,SAASA,SAAT,GAAkE;EAAA,IAA/CC,aAA+C,uEAA/B,CAA+B;;EAC7E,MAAM,CAACC,MAAD,EAASC,SAAT,IAAsBC,cAAA,CAAMC,QAAN,CAAuBJ,aAAvB,CAA5B;;EAEA,MAAMK,QAAQ,GAAG,IAAAC,yCAAA,EAAoBC,CAAD,IAAO;IACvCL,SAAS,CAACK,CAAC,CAACC,WAAF,CAAcC,MAAd,CAAqBR,MAAtB,CAAT;EACH,CAFgB,EAEd,EAFc,CAAjB;EAIA,OAAO,CAACA,MAAD,EAASI,QAAT,CAAP;AACH;;AAAA"}
1
+ {"version":3,"names":["useHeight","initialHeight","height","setHeight","useState","onLayout","useWorkletCallback","e","nativeEvent","layout"],"sources":["useHeight.ts"],"sourcesContent":["import { useState } from 'react';\nimport { ViewProps } from 'react-native';\nimport { useWorkletCallback } from 'react-native-reanimated';\n\ntype OnLayoutCallback = ViewProps['onLayout'];\n\nexport default function useHeight(initialHeight = 0): [number, OnLayoutCallback] {\n const [height, setHeight] = useState<number>(initialHeight);\n\n const onLayout = useWorkletCallback((e) => {\n setHeight(e.nativeEvent.layout.height);\n }, []);\n\n return [height, onLayout];\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAIe,SAASA,SAAT,GAAkE;EAAA,IAA/CC,aAA+C,uEAA/B,CAA+B;EAC7E,MAAM,CAACC,MAAD,EAASC,SAAT,IAAsB,IAAAC,eAAA,EAAiBH,aAAjB,CAA5B;EAEA,MAAMI,QAAQ,GAAG,IAAAC,yCAAA,EAAoBC,CAAD,IAAO;IACvCJ,SAAS,CAACI,CAAC,CAACC,WAAF,CAAcC,MAAd,CAAqBP,MAAtB,CAAT;EACH,CAFgB,EAEd,EAFc,CAAjB;EAIA,OAAO,CAACA,MAAD,EAASG,QAAT,CAAP;AACH;;AAAA"}
@@ -7,7 +7,7 @@ import Divider from '../Divider';
7
7
  import Spacer from '../Spacer';
8
8
  import Typography from '../Typography';
9
9
  import { useTheme } from '../styles';
10
- const ANIMATION_OPTION = {
10
+ const ANIMATION_CONFIG = {
11
11
  duration: 250
12
12
  };
13
13
 
@@ -36,11 +36,11 @@ export default function Accordion(props) {
36
36
  transform: [{
37
37
  rotate: `${rotate.value}deg`
38
38
  }]
39
- }));
39
+ }), []);
40
40
 
41
41
  const onPress = () => {
42
42
  setIsExpanded(prev => !prev);
43
- rotate.value = withTiming(!isExpanded ? 180 : 0, ANIMATION_OPTION);
43
+ rotate.value = withTiming(!isExpanded ? 180 : 0, ANIMATION_CONFIG);
44
44
  };
45
45
 
46
46
  return /*#__PURE__*/React.createElement(Column, null, /*#__PURE__*/React.createElement(ButtonBase, {
@@ -1 +1 @@
1
- {"version":3,"names":["React","useState","Animated","useAnimatedStyle","useSharedValue","withTiming","ChevronDown","ChevronDownIcon","ButtonBase","Column","Divider","Spacer","Typography","useTheme","ANIMATION_OPTION","duration","useStyles","theme","root","flexDirection","paddingVertical","spacing","Accordion","props","content","LeftIcon","RightIcon","title","titleVariant","styles","isExpanded","setIsExpanded","rotate","animatedChevronDownStyles","transform","value","onPress","prev","isValidElement"],"sources":["Accordion.tsx"],"sourcesContent":["import React, { useState } from 'react';\nimport Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { ChevronDown as ChevronDownIcon } from '../internal/icons';\nimport ButtonBase from '../ButtonBase';\nimport Column from '../Column';\nimport Divider from '../Divider';\nimport Spacer from '../Spacer';\nimport Typography from '../Typography';\nimport { useTheme } from '../styles';\n\nimport AccordionProps from './AccordionProps';\n\ntype AccordionStyles = NamedStylesStringUnion<'root'>;\n\nconst ANIMATION_OPTION = { duration: 250 };\n\nconst useStyles: UseStyles<AccordionStyles> = function (): AccordionStyles {\n const theme = useTheme();\n\n return {\n root: {\n flexDirection: 'row',\n paddingVertical: theme.spacing(3),\n },\n };\n};\n\nexport default function Accordion(props: AccordionProps) {\n const {\n content,\n LeftIcon,\n RightIcon,\n title,\n titleVariant = 'subtitle2',\n } = props;\n\n const styles = useStyles();\n\n const [isExpanded, setIsExpanded] = useState(false);\n const rotate = useSharedValue(0);\n\n const animatedChevronDownStyles = useAnimatedStyle(() => ({\n transform: [{ rotate: `${rotate.value}deg` }],\n }));\n\n const onPress = () => {\n setIsExpanded(prev => !prev);\n rotate.value = withTiming(!isExpanded ? 180 : 0, ANIMATION_OPTION);\n };\n\n return (\n <Column>\n <ButtonBase\n onPress={onPress}\n style={styles.root}\n >\n {LeftIcon ? (\n <React.Fragment>\n {LeftIcon}\n <Spacer size={2}/>\n </React.Fragment>\n ) : null}\n\n <Typography\n children={title}\n variant={titleVariant}\n />\n\n <Spacer flex={1}/>\n\n <Spacer size={2}/>\n\n <Column>\n <Animated.View style={animatedChevronDownStyles}>\n {RightIcon ? RightIcon : <ChevronDownIcon/>}\n </Animated.View>\n </Column>\n </ButtonBase>\n\n {isExpanded ? (\n React.isValidElement(content) ? (content) : (\n <Typography\n children={content}\n color={'textSecondary'}\n variant={'body2'}\n />\n )\n ) : null}\n\n <Divider/>\n </Column>\n );\n}\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,QAAhB,Q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GAAoB,CAArB,EAAwBhB,gBAAxB,CAAzB;EACH,CAHD;;EAKA,oBACI,oBAAC,MAAD,qBACI,oBAAC,UAAD;IACI,OAAO,EAAEsB,OADb;IAEI,KAAK,EAAEP,MAAM,CAACX;EAFlB,GAIKO,QAAQ,gBACL,oBAAC,KAAD,CAAO,QAAP,QACKA,QADL,eAEI,oBAAC,MAAD;IAAQ,IAAI,EAAE;EAAd,EAFJ,CADK,GAKL,IATR,eAWI,oBAAC,UAAD;IACI,QAAQ,EAAEE,KADd;IAEI,OAAO,EAAEC;EAFb,EAXJ,eAgBI,oBAAC,MAAD;IAAQ,IAAI,EAAE;EAAd,EAhBJ,eAkBI,oBAAC,MAAD;IAAQ,IAAI,EAAE;EAAd,EAlBJ,eAoBI,oBAAC,MAAD,qBACI,oBAAC,QAAD,CAAU,IAAV;IAAe,KAAK,EAAEK;EAAtB,GACKP,SAAS,GAAGA,SAAH,gBAAe,oBAAC,eAAD,OAD7B,CADJ,CApBJ,CADJ,EA4BKI,UAAU,GACP,aAAA9B,KAAK,CAACsC,cAAN,CAAqBd,OAArB,IAAiCA,OAAjC,gBACI,oBAAC,UAAD;IACI,QAAQ,EAAEA,OADd;IAEI,KAAK,EAAE,eAFX;IAGI,OAAO,EAAE;EAHb,EAFG,GAQP,IApCR,eAsCI,oBAAC,OAAD,OAtCJ,CADJ;AA0CH"}
1
+ {"version":3,"names":["React","useState","Animated","useAnimatedStyle","useSharedValue","withTiming","ChevronDown","ChevronDownIcon","ButtonBase","Column","Divider","Spacer","Typography","useTheme","ANIMATION_CONFIG","duration","useStyles","theme","root","flexDirection","paddingVertical","spacing","Accordion","props","content","LeftIcon","RightIcon","title","titleVariant","styles","isExpanded","setIsExpanded","rotate","animatedChevronDownStyles","transform","value","onPress","prev","isValidElement"],"sources":["Accordion.tsx"],"sourcesContent":["import React, { useState } from 'react';\nimport type { WithTimingConfig } from 'react-native-reanimated';\nimport Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { ChevronDown as ChevronDownIcon } from '../internal/icons';\nimport ButtonBase from '../ButtonBase';\nimport Column from '../Column';\nimport Divider from '../Divider';\nimport Spacer from '../Spacer';\nimport Typography from '../Typography';\nimport { useTheme } from '../styles';\n\nimport AccordionProps from './AccordionProps';\n\ntype AccordionStyles = NamedStylesStringUnion<'root'>;\n\nconst ANIMATION_CONFIG: Readonly<WithTimingConfig> = { duration: 250 };\n\nconst useStyles: UseStyles<AccordionStyles> = function (): AccordionStyles {\n const theme = useTheme();\n\n return {\n root: {\n flexDirection: 'row',\n paddingVertical: theme.spacing(3),\n },\n };\n};\n\nexport default function Accordion(props: AccordionProps) {\n const {\n content,\n LeftIcon,\n RightIcon,\n title,\n titleVariant = 'subtitle2',\n } = props;\n\n const styles = useStyles();\n\n const [isExpanded, setIsExpanded] = useState(false);\n\n const rotate = useSharedValue(0);\n\n const animatedChevronDownStyles = useAnimatedStyle(() => ({\n transform: [{ rotate: `${rotate.value}deg` }],\n }), []);\n\n const onPress = () => {\n setIsExpanded(prev => !prev);\n rotate.value = withTiming(!isExpanded ? 180 : 0, ANIMATION_CONFIG);\n };\n\n return (\n <Column>\n <ButtonBase\n onPress={onPress}\n style={styles.root}\n >\n {LeftIcon ? (\n <React.Fragment>\n {LeftIcon}\n <Spacer size={2}/>\n </React.Fragment>\n ) : null}\n\n <Typography\n children={title}\n variant={titleVariant}\n />\n\n <Spacer flex={1}/>\n\n <Spacer size={2}/>\n\n <Column>\n <Animated.View style={animatedChevronDownStyles}>\n {RightIcon ? RightIcon : <ChevronDownIcon/>}\n </Animated.View>\n </Column>\n </ButtonBase>\n\n {isExpanded ? (\n React.isValidElement(content) ? (content) : (\n <Typography\n children={content}\n color={'textSecondary'}\n variant={'body2'}\n />\n )\n ) : null}\n\n <Divider/>\n </Column>\n );\n}\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,QAAhB,QAAgC,OAAhC;AAEA,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oB,CAArB,EAAwBhB,gBAAxB,CAAzB;EACH,CAHD;;EAKA,oBACI,oBAAC,MAAD,qBACI,oBAAC,UAAD;IACI,OAAO,EAAEsB,OADb;IAEI,KAAK,EAAEP,MAAM,CAACX;EAFlB,GAIKO,QAAQ,gBACL,oBAAC,KAAD,CAAO,QAAP,QACKA,QADL,eAEI,oBAAC,MAAD;IAAQ,IAAI,EAAE;EAAd,EAFJ,CADK,GAKL,IATR,eAWI,oBAAC,UAAD;IACI,QAAQ,EAAEE,KADd;IAEI,OAAO,EAAEC;EAFb,EAXJ,eAgBI,oBAAC,MAAD;IAAQ,IAAI,EAAE;EAAd,EAhBJ,eAkBI,oBAAC,MAAD;IAAQ,IAAI,EAAE;EAAd,EAlBJ,eAoBI,oBAAC,MAAD,qBACI,oBAAC,QAAD,CAAU,IAAV;IAAe,KAAK,EAAEK;EAAtB,GACKP,SAAS,GAAGA,SAAH,gBAAe,oBAAC,eAAD,OAD7B,CADJ,CApBJ,CADJ,EA4BKI,UAAU,GACP,aAAA9B,KAAK,CAACsC,cAAN,CAAqBd,OAArB,IAAiCA,OAAjC,gBACI,oBAAC,UAAD;IACI,QAAQ,EAAEA,OADd;IAEI,KAAK,EAAE,eAFX;IAGI,OAAO,EAAE;EAHb,EAFG,GAQP,IApCR,eAsCI,oBAAC,OAAD,OAtCJ,CADJ;AA0CH"}
@@ -1,27 +1,26 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
- import React from 'react';
4
- import { useAnimatedStyle, useSharedValue, withDelay, withTiming } from 'react-native-reanimated';
3
+ import React, { useCallback, useEffect, useRef } from 'react';
4
+ import { Animated } from 'react-native';
5
5
  import { useThrottle } from '../hooks';
6
6
  import { AnimatedPressable } from '../animated';
7
- import { StyleSheet } from '../styles';
8
- import useDisabledReaction from './useDisabledReaction';
9
7
  export const ORIGINAL_OPACITY = 1;
10
8
  export const DISABLED_OPACITY = .3;
11
9
  const ACTIVE_OPACITY = .65;
12
10
  const ORIGINAL_SCALE = 1;
13
- const MINIFIED_SCALE = .96;
14
- const animationTimingConfig = {
15
- duration: 150
11
+ const MINIFIED_SCALE = .96; // at "node_modules/react-native/Libraries/Pressability.js"
12
+ // const DEFAULT_MIN_PRESS_DURATION = 130;
13
+
14
+ const PRESS_IN_DELAY = 130;
15
+
16
+ const startTimingAnimationWithDefaults = (value, toValue) => {
17
+ Animated.timing(value, {
18
+ toValue,
19
+ duration: 150,
20
+ useNativeDriver: true
21
+ }).start();
16
22
  };
17
- const styles = StyleSheet.create({
18
- disabled: {
19
- opacity: DISABLED_OPACITY,
20
- transform: [{
21
- scale: ORIGINAL_SCALE
22
- }]
23
- }
24
- });
23
+
25
24
  export default function ButtonBase(props) {
26
25
  const {
27
26
  children,
@@ -29,7 +28,7 @@ export default function ButtonBase(props) {
29
28
  disableThrottle = false,
30
29
  onPress,
31
30
  pressEffect = 'opacity',
32
- style,
31
+ style: styleProp,
33
32
  throttleMillis = 650,
34
33
  ...otherProps
35
34
  } = props;
@@ -37,51 +36,58 @@ export default function ButtonBase(props) {
37
36
  periodMillis: disableThrottle ? 0 : throttleMillis,
38
37
  callback: onPress
39
38
  });
40
- const opacity = useSharedValue(ORIGINAL_OPACITY);
41
- const scale = useSharedValue(ORIGINAL_SCALE);
42
- const animatedStyle = useAnimatedStyle(() => ({
43
- opacity: opacity.value,
44
- transform: [{
45
- scale: scale.value
46
- }]
47
- }));
48
- useDisabledReaction(disabled, opacity);
49
-
50
- const startAnimation = function (pressIn) {
51
- let isHovered = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
52
-
53
- if (pressEffect === 'none') {
54
- return;
39
+ const opacity = useRef(new Animated.Value(ORIGINAL_OPACITY)).current;
40
+ const scale = useRef(new Animated.Value(ORIGINAL_SCALE)).current;
41
+ useEffect(() => {
42
+ opacity.setValue(disabled ? DISABLED_OPACITY : ORIGINAL_OPACITY);
43
+ }, [disabled]);
44
+ const startScaleAnimation = useCallback((pressIn, isHover) => {
45
+ if (!isHover) {
46
+ startTimingAnimationWithDefaults(scale, pressIn ? MINIFIED_SCALE : ORIGINAL_SCALE);
47
+ }
48
+ }, []);
49
+ const startOpacityAnimation = useCallback(pressIn => {
50
+ if (pressIn) {
51
+ opacity.setValue(ACTIVE_OPACITY);
52
+ } else {
53
+ startTimingAnimationWithDefaults(opacity, ORIGINAL_OPACITY);
55
54
  }
55
+ }, []);
56
+ const startPressAnimation = useCallback(function (pressIn) {
57
+ let isHover = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
56
58
 
57
- if (pressEffect === 'opacity') {
58
- if (pressIn) {
59
- opacity.value = ACTIVE_OPACITY;
60
- } else {
61
- opacity.value = withTiming(ORIGINAL_OPACITY, animationTimingConfig);
62
- }
63
- } else if (!isHovered) {
64
- if (pressIn) {
65
- scale.value = withDelay(100, withTiming(MINIFIED_SCALE, animationTimingConfig));
66
- } else {
67
- scale.value = withTiming(ORIGINAL_SCALE, animationTimingConfig);
68
- }
59
+ if (pressEffect === 'scale') {
60
+ startScaleAnimation(pressIn, isHover);
61
+ } else if (pressEffect === 'opacity') {
62
+ startOpacityAnimation(pressIn, isHover);
69
63
  }
64
+ }, [pressEffect]);
65
+ const handlePressIn = useCallback(() => {
66
+ startPressAnimation(true, false);
67
+ }, [startPressAnimation]);
68
+ const handlePressOut = useCallback(() => {
69
+ startPressAnimation(false, false);
70
+ }, [startPressAnimation]);
71
+ const animatedStyle = {
72
+ opacity,
73
+ transform: [{
74
+ scale
75
+ }]
70
76
  };
71
-
72
77
  return /*#__PURE__*/React.createElement(AnimatedPressable, _extends({
73
78
  disabled: disabled,
74
79
  onPress: handlePress,
75
- onPressIn: () => startAnimation(true),
76
- onPressOut: () => startAnimation(false),
77
- style: [animatedStyle, disabled ? styles.disabled : undefined, style]
80
+ onPressIn: handlePressIn,
81
+ onPressOut: handlePressOut,
82
+ style: [animatedStyle, styleProp],
83
+ unstable_pressDelay: PRESS_IN_DELAY
78
84
  }, otherProps), typeof children !== 'function' ? _ref => {
79
85
  let {
80
86
  hovered
81
87
  } = _ref;
82
88
 
83
89
  if (hovered !== undefined && !disabled) {
84
- startAnimation(hovered, true);
90
+ startPressAnimation(hovered, true);
85
91
  }
86
92
 
87
93
  return children;
@@ -1 +1 @@
1
- {"version":3,"names":["React","useAnimatedStyle","useSharedValue","withDelay","withTiming","useThrottle","AnimatedPressable","StyleSheet","useDisabledReaction","ORIGINAL_OPACITY","DISABLED_OPACITY","ACTIVE_OPACITY","ORIGINAL_SCALE","MINIFIED_SCALE","animationTimingConfig","duration","styles","create","disabled","opacity","transform","scale","ButtonBase","props","children","disableThrottle","onPress","pressEffect","style","throttleMillis","otherProps","handlePress","periodMillis","callback","animatedStyle","value","startAnimation","pressIn","isHovered","undefined","hovered"],"sources":["ButtonBase.tsx"],"sourcesContent":["import React from 'react';\nimport type { WithTimingConfig } from 'react-native-reanimated';\nimport { useAnimatedStyle, useSharedValue, withDelay, withTiming } from 'react-native-reanimated';\nimport { useThrottle } from '../hooks';\nimport { AnimatedPressable } from '../animated';\nimport { StyleSheet } from '../styles';\nimport type ButtonBaseProps from './ButtonBaseProps';\nimport useDisabledReaction from './useDisabledReaction';\n\nexport const ORIGINAL_OPACITY = 1;\nexport const DISABLED_OPACITY = .3;\nconst ACTIVE_OPACITY = .65;\n\nconst ORIGINAL_SCALE = 1;\nconst MINIFIED_SCALE = .96;\n\nconst animationTimingConfig: WithTimingConfig = { duration: 150 };\n\nconst styles = StyleSheet.create({\n disabled: {\n opacity: DISABLED_OPACITY,\n transform: [{ scale: ORIGINAL_SCALE }],\n },\n});\n\nexport default function ButtonBase(props: ButtonBaseProps) {\n const {\n children,\n disabled = false,\n disableThrottle = false,\n onPress,\n pressEffect = 'opacity',\n style,\n throttleMillis = 650,\n ...otherProps\n } = props;\n\n const handlePress = useThrottle({\n periodMillis: disableThrottle ? 0 : throttleMillis,\n callback: onPress,\n });\n\n const opacity = useSharedValue(ORIGINAL_OPACITY);\n const scale = useSharedValue(ORIGINAL_SCALE);\n\n const animatedStyle = useAnimatedStyle(() => ({\n opacity: opacity.value,\n transform: [{ scale: scale.value }],\n }));\n\n useDisabledReaction(disabled, opacity);\n\n const startAnimation = (pressIn: boolean, isHovered: boolean = false) => {\n if (pressEffect === 'none') {\n return;\n }\n\n if (pressEffect === 'opacity') {\n if (pressIn) {\n opacity.value = ACTIVE_OPACITY;\n } else {\n opacity.value = withTiming(ORIGINAL_OPACITY, animationTimingConfig);\n }\n } else if (!isHovered) {\n if (pressIn) {\n scale.value = withDelay(\n 100,\n withTiming(MINIFIED_SCALE, animationTimingConfig),\n );\n } else {\n scale.value = withTiming(ORIGINAL_SCALE, animationTimingConfig);\n }\n }\n };\n\n return (\n <AnimatedPressable\n disabled={disabled}\n onPress={handlePress}\n onPressIn={() => startAnimation(true)}\n onPressOut={() => startAnimation(false)}\n style={[\n animatedStyle,\n disabled ? styles.disabled : undefined,\n style,\n ]}\n {...otherProps}\n >\n {typeof children !== 'function' ? (\n ({ hovered }) => {\n if (hovered !== undefined && !disabled) {\n startAnimation(hovered, true);\n }\n\n return children;\n }\n ) : children}\n </AnimatedPressable>\n );\n};\n"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAEA,SAASC,gBAAT,EAA2BC,cAA3B,EAA2CC,SAA3C,EAAsDC,UAAtD,QAAwE,yBAAxE;AACA,SAASC,WAAT,QAA4B,UAA5B;AACA,SAASC,iBAAT,QAAkC,aAAlC;AACA,SAASC,UAAT,QAA2B,WAA3B;AAEA,OAAOC,mBAAP,MAAgC,uBAAhC;AAEA,OAAO,MAAMC,gBAAgB,GAAG,CAAzB;AACP,OAAO,MAAMC,gBAAgB,GAAG,EAAzB;AACP,MAAMC,cAAc,GAAG,GAAvB;AAEA,MAAMC,cAAc,GAAG,CAAvB;AACA,MAAM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ACHQ,OAAO,CAACgB,KAAR,GAAgB/B,UAAU,CAACK,gBAAD,EAAmBK,qBAAnB,CAA1B;MACH;IACJ,CAND,MAMO,IAAI,CAACwB,SAAL,EAAgB;MACnB,IAAID,OAAJ,EAAa;QACThB,KAAK,CAACc,KAAN,GAAchC,SAAS,CACnB,GADmB,EAEnBC,UAAU,CAACS,cAAD,EAAiBC,qBAAjB,CAFS,CAAvB;MAIH,CALD,MAKO;QACHO,KAAK,CAACc,KAAN,GAAc/B,UAAU,CAACQ,cAAD,EAAiBE,qBAAjB,CAAxB;MACH;IACJ;EACJ,CArBD;;EAuBA,oBACI,oBAAC,iBAAD;IACI,QAAQ,EAAEI,QADd;IAEI,OAAO,EAAEa,WAFb;IAGI,SAAS,EAAE,MAAMK,cAAc,CAAC,IAAD,CAHnC;IAII,UAAU,EAAE,MAAMA,cAAc,CAAC,KAAD,CAJpC;IAKI,KAAK,EAAE,CACHF,aADG,EAEHhB,QAAQ,GAAGF,MAAM,CAACE,QAAV,GAAqBqB,SAF1B,EAGHX,KAHG;EALX,GAUQE,UAVR,GAYK,OAAON,QAAP,KAAoB,UAApB,GACG,QAAiB;IAAA,IAAhB;MAAEgB;IAAF,CAAgB;;IACb,IAAIA,OAAO,KAAKD,SAAZ,IAAyB,CAACrB,QAA9B,EAAwC;MACpCkB,cAAc,CAACI,OAAD,EAAU,IAAV,CAAd;IACH;;IAED,OAAOhB,QAAP;EACH,CAPJ,GAQGA,QApBR,CADJ;AAwBH;AAAA"}
1
+ {"version":3,"names":["React","useCallback","useEffect","useRef","Animated","useThrottle","AnimatedPressable","ORIGINAL_OPACITY","DISABLED_OPACITY","ACTIVE_OPACITY","ORIGINAL_SCALE","MINIFIED_SCALE","PRESS_IN_DELAY","startTimingAnimationWithDefaults","value","toValue","timing","duration","useNativeDriver","start","ButtonBase","props","children","disabled","disableThrottle","onPress","pressEffect","style","styleProp","throttleMillis","otherProps","handlePress","periodMillis","callback","opacity","Value","current","scale","setValue","startScaleAnimation","pressIn","isHover","startOpacityAnimation","startPressAnimation","handlePressIn","handlePressOut","animatedStyle","transform","hovered","undefined"],"sources":["ButtonBase.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useRef } from 'react';\nimport { Animated } from 'react-native';\nimport { useThrottle } from '../hooks';\nimport { AnimatedPressable } from '../animated';\nimport type ButtonBaseProps from './ButtonBaseProps';\n\ninterface StartPressAnimation {\n (pressIn: boolean, isHover: boolean): void;\n}\n\nexport const ORIGINAL_OPACITY = 1;\nexport const DISABLED_OPACITY = .3;\nconst ACTIVE_OPACITY = .65;\n\nconst ORIGINAL_SCALE = 1;\nconst MINIFIED_SCALE = .96;\n\n// at \"node_modules/react-native/Libraries/Pressability.js\"\n// const DEFAULT_MIN_PRESS_DURATION = 130;\nconst PRESS_IN_DELAY = 130;\n\ntype TimingAnimationValue = Animated.Value | Animated.ValueXY;\ntype TimingAnimationToValue = Animated.TimingAnimationConfig['toValue'];\n\nconst startTimingAnimationWithDefaults = (\n value: TimingAnimationValue,\n toValue: TimingAnimationToValue,\n) => {\n Animated.timing(value, {\n toValue,\n duration: 150,\n useNativeDriver: true,\n }).start();\n};\n\nexport default function ButtonBase(props: ButtonBaseProps) {\n const {\n children,\n disabled = false,\n disableThrottle = false,\n onPress,\n pressEffect = 'opacity',\n style: styleProp,\n throttleMillis = 650,\n ...otherProps\n } = props;\n\n const handlePress = useThrottle({\n periodMillis: disableThrottle ? 0 : throttleMillis,\n callback: onPress,\n });\n\n const opacity = useRef<Animated.Value>(new Animated.Value(ORIGINAL_OPACITY)).current;\n const scale = useRef<Animated.Value>(new Animated.Value(ORIGINAL_SCALE)).current;\n\n useEffect(() => {\n opacity.setValue(disabled ? DISABLED_OPACITY : ORIGINAL_OPACITY);\n }, [disabled]);\n\n const startScaleAnimation = useCallback<StartPressAnimation>((pressIn, isHover) => {\n if (!isHover) {\n startTimingAnimationWithDefaults(\n scale,\n pressIn ? MINIFIED_SCALE : ORIGINAL_SCALE,\n );\n }\n }, []);\n\n const startOpacityAnimation = useCallback<StartPressAnimation>((pressIn) => {\n if (pressIn) {\n opacity.setValue(ACTIVE_OPACITY);\n } else {\n startTimingAnimationWithDefaults(opacity, ORIGINAL_OPACITY);\n }\n }, []);\n\n const startPressAnimation = useCallback<StartPressAnimation>((pressIn, isHover = false) => {\n if (pressEffect === 'scale') {\n startScaleAnimation(pressIn, isHover);\n } else if (pressEffect === 'opacity') {\n startOpacityAnimation(pressIn, isHover);\n }\n }, [pressEffect]);\n\n const handlePressIn = useCallback(() => {\n startPressAnimation(true, false);\n }, [startPressAnimation]);\n\n const handlePressOut = useCallback(() => {\n startPressAnimation(false, false);\n }, [startPressAnimation]);\n\n const animatedStyle = {\n opacity,\n transform: [{ scale }],\n };\n\n return (\n <AnimatedPressable\n disabled={disabled}\n onPress={handlePress}\n onPressIn={handlePressIn}\n onPressOut={handlePressOut}\n style={[\n animatedStyle,\n styleProp,\n ]}\n unstable_pressDelay={PRESS_IN_DELAY}\n {...otherProps}\n >\n {typeof children !== 'function' ? (\n ({ hovered }) => {\n if (hovered !== undefined && !disabled) {\n startPressAnimation(hovered, true);\n }\n\n return children;\n }\n ) : children}\n </AnimatedPressable>\n );\n};\n"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,WAAhB,EAA6BC,SAA7B,EAAwCC,MAAxC,QAAsD,OAAtD;AACA,SAASC,QAAT,QAAyB,cAAzB;AACA,SAASC,WAAT,QAA4B,UAA5B;AACA,SAASC,iBAAT,QAAkC,aAAlC;AAOA,OAAO,MAAMC,gBAAgB,GAAG,CAAzB;AACP,OAAO,MAAMC,gBAAgB,GAAG,EAAzB;AACP,MAAMC,cAAc,GAAG,GAAvB;AAEA,MAAMC,cAAc,GAAG,CAAvB;AACA,MAAMC,cAAc,GAAG,GAAvB,C,CAEA;AACA;;AACA,MAAMC,cAAc,GAAG,GAAvB;;AAKA,MAAMC,gCAAgC,GAAG,CACrCC,KADqC,EAErCC,OAFqC,KAGpC;EACDX,QAAQ,CAACY,MAAT,CA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ED,OAAO1B,QAAP;EACH,CAPJ,GAQGA,QApBR,CADJ;AAwBH;AAAA"}
@@ -1,7 +1,12 @@
1
- import React from 'react';
2
- import Animated, { Easing, interpolate, useAnimatedStyle, useSharedValue, withRepeat, withTiming } from 'react-native-reanimated';
1
+ import React, { useEffect } from 'react';
2
+ import Animated, { Easing, useAnimatedStyle, useSharedValue, withRepeat, withTiming } from 'react-native-reanimated';
3
3
  import { CircularProgress as CircularProgressIcon } from '../internal/icons';
4
- import { css } from '../styles';
4
+ const ANIMATION_CONFIG = {
5
+ duration: 900,
6
+ easing: Easing.linear
7
+ };
8
+ const MIN_ROTATE_DEGREE = 0;
9
+ const MAX_ROTATE_DEGREE = 360;
5
10
 
6
11
  const useStyles = function () {
7
12
  return {
@@ -14,28 +19,22 @@ const useStyles = function () {
14
19
 
15
20
  export default function CircularProgress(props) {
16
21
  const {
17
- style
22
+ style: styleProp
18
23
  } = props;
19
24
  const styles = useStyles();
20
- const rootStyle = css([styles.root, style]);
21
- const sharedSpin = useSharedValue(0);
22
- const spinStyle = useAnimatedStyle(() => {
23
- const interpolatedSpin = interpolate(sharedSpin.value, [0, 1], [0, 360]);
24
- return {
25
- transform: [{
26
- rotate: `${interpolatedSpin}deg`
27
- }]
28
- };
29
- });
30
- React.useEffect(() => {
31
- sharedSpin.value = withRepeat(withTiming(1, {
32
- duration: 900,
33
- easing: Easing.linear
34
- }), -1, false);
25
+ const rotate = useSharedValue(MIN_ROTATE_DEGREE);
26
+ const animatedStyle = useAnimatedStyle(() => ({
27
+ transform: [{
28
+ rotate: `${rotate.value}deg`
29
+ }]
30
+ }), []);
31
+ useEffect(() => {
32
+ rotate.value = withRepeat(withTiming(MAX_ROTATE_DEGREE, ANIMATION_CONFIG), -1, false);
35
33
  }, []);
36
34
  return /*#__PURE__*/React.createElement(Animated.View, {
37
- style: [spinStyle, rootStyle]
38
- }, /*#__PURE__*/React.createElement(CircularProgressIcon, null));
35
+ children: /*#__PURE__*/React.createElement(CircularProgressIcon, null),
36
+ style: [animatedStyle, styles.root, styleProp]
37
+ });
39
38
  }
40
39
  ;
41
40
  //# sourceMappingURL=CircularProgress.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","Animated","Easing","interpolate","useAnimatedStyle","useSharedValue","withRepeat","withTiming","CircularProgress","CircularProgressIcon","css","useStyles","root","alignItems","justifyContent","props","style","styles","rootStyle","sharedSpin","spinStyle","interpolatedSpin","value","transform","rotate","useEffect","duration","easing","linear"],"sources":["CircularProgress.tsx"],"sourcesContent":["import React from 'react';\nimport { ViewProps } from 'react-native';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport Animated, {\n Easing,\n interpolate,\n useAnimatedStyle,\n useSharedValue,\n withRepeat,\n withTiming,\n} from 'react-native-reanimated';\nimport { CircularProgress as CircularProgressIcon } from '../internal/icons';\nimport { css } from '../styles';\nimport { OverridableComponentProps } from '../types';\n\ntype CircularProgressStyles = NamedStylesStringUnion<'root'>;\n\nconst useStyles: UseStyles<CircularProgressStyles> = function (): CircularProgressStyles {\n return {\n root: {\n alignItems: 'center',\n justifyContent: 'center',\n },\n };\n};\n\nexport default function CircularProgress(props: OverridableComponentProps<ViewProps>) {\n const { style } = props;\n\n const styles = useStyles();\n\n const rootStyle = css([\n styles.root,\n style,\n ]);\n\n const sharedSpin = useSharedValue(0);\n\n const spinStyle = useAnimatedStyle(() => {\n const interpolatedSpin = interpolate(sharedSpin.value, [0, 1], [0, 360]);\n\n return {\n transform: [{ rotate: `${interpolatedSpin}deg` }],\n };\n });\n\n React.useEffect(() => {\n sharedSpin.value = withRepeat(\n withTiming(1, { duration: 900, easing: Easing.linear }),\n -1,\n false,\n );\n }, []);\n\n return (\n <Animated.View style={[spinStyle, rootStyle]}>\n <CircularProgressIcon/>\n </Animated.View>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAGA,OAAOC,QAAP,IACIC,MADJ,EAEIC,WAFJ,EAGIC,gBAHJ,EAIIC,cA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AA"}
1
+ {"version":3,"names":["React","useEffect","Animated","Easing","useAnimatedStyle","useSharedValue","withRepeat","withTiming","CircularProgress","CircularProgressIcon","ANIMATION_CONFIG","duration","easing","linear","MIN_ROTATE_DEGREE","MAX_ROTATE_DEGREE","useStyles","root","alignItems","justifyContent","props","style","styleProp","styles","rotate","animatedStyle","transform","value"],"sources":["CircularProgress.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport { ViewProps } from 'react-native';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport type { WithTimingConfig } from 'react-native-reanimated';\nimport Animated, { Easing, useAnimatedStyle, useSharedValue, withRepeat, withTiming } from 'react-native-reanimated';\nimport { CircularProgress as CircularProgressIcon } from '../internal/icons';\nimport { OverridableComponentProps } from '../types';\n\ntype CircularProgressStyles = NamedStylesStringUnion<'root'>;\n\nconst ANIMATION_CONFIG: Readonly<WithTimingConfig> = { duration: 900, easing: Easing.linear };\n\nconst MIN_ROTATE_DEGREE = 0;\nconst MAX_ROTATE_DEGREE = 360;\n\nconst useStyles: UseStyles<CircularProgressStyles> = function (): CircularProgressStyles {\n return {\n root: {\n alignItems: 'center',\n justifyContent: 'center',\n },\n };\n};\n\nexport default function CircularProgress(props: OverridableComponentProps<ViewProps>) {\n const { style: styleProp } = props;\n\n const styles = useStyles();\n\n const rotate = useSharedValue(MIN_ROTATE_DEGREE);\n\n const animatedStyle = useAnimatedStyle(() => ({\n transform: [{ rotate: `${rotate.value}deg` }],\n }), []);\n\n useEffect(() => {\n rotate.value = withRepeat(\n withTiming(MAX_ROTATE_DEGREE, ANIMATION_CONFIG),\n -1,\n false,\n );\n }, []);\n\n return (\n <Animated.View\n children={<CircularProgressIcon/>}\n style={[\n animatedStyle,\n styles.root,\n styleProp,\n ]}\n />\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,SAAhB,QAAiC,OAAjC;AAIA,OAAOC,QAAP,IAAmBC,MAAnB,EAA2BC,gBAA3B,EAA6CC,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