@one-am/react-native-simple-image-slider 0.2.2 → 0.3.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.
Files changed (72) hide show
  1. package/README.md +26 -3
  2. package/lib/commonjs/@types/icons.js +6 -0
  3. package/lib/commonjs/@types/icons.js.map +1 -0
  4. package/lib/commonjs/@types/pinch-to-zoom.js +6 -0
  5. package/lib/commonjs/@types/pinch-to-zoom.js.map +1 -0
  6. package/lib/commonjs/@types/slider.js +6 -0
  7. package/lib/commonjs/@types/slider.js.map +1 -0
  8. package/lib/commonjs/BaseSimpleImageSlider.js +9 -3
  9. package/lib/commonjs/BaseSimpleImageSlider.js.map +1 -1
  10. package/lib/commonjs/FullScreenImageSlider.js +21 -8
  11. package/lib/commonjs/FullScreenImageSlider.js.map +1 -1
  12. package/lib/commonjs/PageCounter.js +26 -24
  13. package/lib/commonjs/PageCounter.js.map +1 -1
  14. package/lib/commonjs/PinchToZoom.js +14 -16
  15. package/lib/commonjs/PinchToZoom.js.map +1 -1
  16. package/lib/commonjs/SimpleImageSlider.js +4 -1
  17. package/lib/commonjs/SimpleImageSlider.js.map +1 -1
  18. package/lib/commonjs/icons/IconX.js +42 -0
  19. package/lib/commonjs/icons/IconX.js.map +1 -0
  20. package/lib/commonjs/index.js +7 -0
  21. package/lib/commonjs/index.js.map +1 -1
  22. package/lib/module/@types/icons.js +2 -0
  23. package/lib/module/@types/icons.js.map +1 -0
  24. package/lib/module/@types/pinch-to-zoom.js +2 -0
  25. package/lib/module/@types/pinch-to-zoom.js.map +1 -0
  26. package/lib/module/@types/slider.js +2 -0
  27. package/lib/module/@types/slider.js.map +1 -0
  28. package/lib/module/BaseSimpleImageSlider.js +9 -3
  29. package/lib/module/BaseSimpleImageSlider.js.map +1 -1
  30. package/lib/module/FullScreenImageSlider.js +21 -8
  31. package/lib/module/FullScreenImageSlider.js.map +1 -1
  32. package/lib/module/PageCounter.js +26 -23
  33. package/lib/module/PageCounter.js.map +1 -1
  34. package/lib/module/PinchToZoom.js +14 -16
  35. package/lib/module/PinchToZoom.js.map +1 -1
  36. package/lib/module/SimpleImageSlider.js +4 -1
  37. package/lib/module/SimpleImageSlider.js.map +1 -1
  38. package/lib/module/icons/IconX.js +33 -0
  39. package/lib/module/icons/IconX.js.map +1 -0
  40. package/lib/module/index.js +2 -1
  41. package/lib/module/index.js.map +1 -1
  42. package/lib/typescript/src/@types/icons.d.ts +6 -0
  43. package/lib/typescript/src/@types/icons.d.ts.map +1 -0
  44. package/lib/typescript/src/@types/pinch-to-zoom.d.ts +9 -0
  45. package/lib/typescript/src/@types/pinch-to-zoom.d.ts.map +1 -0
  46. package/lib/typescript/src/@types/slider.d.ts +5 -0
  47. package/lib/typescript/src/@types/slider.d.ts.map +1 -0
  48. package/lib/typescript/src/BaseSimpleImageSlider.d.ts +10 -8
  49. package/lib/typescript/src/BaseSimpleImageSlider.d.ts.map +1 -1
  50. package/lib/typescript/src/FullScreenImageSlider.d.ts +38 -3
  51. package/lib/typescript/src/FullScreenImageSlider.d.ts.map +1 -1
  52. package/lib/typescript/src/PageCounter.d.ts +9 -0
  53. package/lib/typescript/src/PageCounter.d.ts.map +1 -1
  54. package/lib/typescript/src/PinchToZoom.d.ts +36 -6
  55. package/lib/typescript/src/PinchToZoom.d.ts.map +1 -1
  56. package/lib/typescript/src/SimpleImageSlider.d.ts +13 -1
  57. package/lib/typescript/src/SimpleImageSlider.d.ts.map +1 -1
  58. package/lib/typescript/src/icons/IconX.d.ts +5 -0
  59. package/lib/typescript/src/icons/IconX.d.ts.map +1 -0
  60. package/lib/typescript/src/index.d.ts +3 -1
  61. package/lib/typescript/src/index.d.ts.map +1 -1
  62. package/package.json +3 -5
  63. package/src/@types/icons.ts +6 -0
  64. package/src/@types/pinch-to-zoom.ts +9 -0
  65. package/src/@types/slider.ts +5 -0
  66. package/src/BaseSimpleImageSlider.tsx +13 -16
  67. package/src/FullScreenImageSlider.tsx +49 -16
  68. package/src/PageCounter.tsx +26 -25
  69. package/src/PinchToZoom.tsx +49 -28
  70. package/src/SimpleImageSlider.tsx +10 -5
  71. package/src/icons/IconX.tsx +24 -0
  72. package/src/index.tsx +5 -0
@@ -1,14 +1,11 @@
1
1
  import React, { type ReactElement } from 'react';
2
2
  import { FlashList } from '@shopify/flash-list';
3
- import { type ImageProps } from 'expo-image';
4
3
  import { type StyleProp, type ViewStyle } from 'react-native';
5
- import { type SharedValue } from 'react-native-reanimated';
4
+ import { type PinchToZoomProps } from './PinchToZoom';
6
5
  import { type RenderProp } from './utils/renderProp';
7
- export type SimpleImageSliderItem = ImageProps & {
8
- key: string;
9
- };
6
+ import type { SimpleImageSliderItem } from './@types/slider';
10
7
  export type BaseSimpleImageSliderProps = {
11
- data: SimpleImageSliderItem[] | undefined;
8
+ data: SimpleImageSliderItem[];
12
9
  style?: StyleProp<ViewStyle>;
13
10
  imageWidth?: number;
14
11
  imageHeight?: number;
@@ -25,9 +22,14 @@ export type BaseSimpleImageSliderProps = {
25
22
  indexOverride?: number;
26
23
  onViewableItemChange?: (index: number) => void;
27
24
  enablePinchToZoom?: boolean;
28
- onPinchToZoomTranslationChange?: (x: SharedValue<number>, y: SharedValue<number>, scale: SharedValue<number>) => void;
29
- onPinchToZoomRequestClose?: () => void;
25
+ onPinchToZoomStatusChange?: PinchToZoomProps['onTranslationChange'];
26
+ onPinchToZoomRequestClose?: PinchToZoomProps['onDismiss'];
30
27
  };
28
+ /**
29
+ * @description A simple image slider that displays a list of images. This is the component
30
+ * that {@link SimpleImageSlider} and {@link FullScreenImageSlider}
31
+ * are built upon. You should normally use one of those two components instead of this one.
32
+ */
31
33
  declare const BaseListImageSlider: React.ForwardRefExoticComponent<BaseSimpleImageSliderProps & React.RefAttributes<FlashList<SimpleImageSliderItem>>>;
32
34
  export default BaseListImageSlider;
33
35
  //# sourceMappingURL=BaseSimpleImageSlider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BaseSimpleImageSlider.d.ts","sourceRoot":"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KAAK,IAAI,CAAC;IACnE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,mBAAmB,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,aAAa,GAAG,cAAc,CAAC;IAChF,iBAAiB,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,YAAY,CAAC;IAC9E,iBAAiB,CAAC,EAAE,UAAU,CAAC;IAC/B,gBAAgB,CAAC,EAAE,UAAU,CAAC;IAC9B,oBAAoB,CAAC,EAAE,UAAU,CAAC;IAClC,mBAAmB,CAAC,EAAE,UAAU,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,yBAAyB,CAAC,EAAE,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;IACpE,yBAAyB,CAAC,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CAC7D,CAAC;AAqEF;;;;GAIG;AACH,QAAA,MAAM,mBAAmB,qHAgKvB,CAAC;AAEH,eAAe,mBAAmB,CAAC"}
@@ -1,15 +1,50 @@
1
1
  import React, { type ReactNode } from 'react';
2
2
  import { FlashList } from '@shopify/flash-list';
3
- import { type BaseSimpleImageSliderProps, type SimpleImageSliderItem } from './BaseSimpleImageSlider';
3
+ import { type BaseSimpleImageSliderProps } from './BaseSimpleImageSlider';
4
+ import type { SimpleImageSliderItem } from './@types/slider';
5
+ import { type RenderProp } from './utils/renderProp';
4
6
  export type FullScreenImageSliderProps = BaseSimpleImageSliderProps & {
7
+ /**
8
+ * @description Whether the modal is open or not.
9
+ */
5
10
  open?: boolean;
11
+ /**
12
+ * @description Callback that is called when the modal is requested to be closed.
13
+ */
6
14
  onRequestClose?: () => void;
7
- renderDescription?: (index: number) => ReactNode;
15
+ /**
16
+ * @description Callback that renders an element to be displayed as the description of the current image.
17
+ * @param item The current item being displayed.
18
+ * @param index The index of the current item being displayed.
19
+ */
20
+ renderDescription?: (item: SimpleImageSliderItem, index: number) => ReactNode;
21
+ /**
22
+ * @description Item to be rendered in place of the default close button icon.
23
+ */
24
+ CloseButtonIcon?: RenderProp;
8
25
  };
26
+ /**
27
+ * @description A full screen image slider that displays images in a modal.
28
+ */
9
29
  declare const FullScreenImageSlider: React.ForwardRefExoticComponent<BaseSimpleImageSliderProps & {
30
+ /**
31
+ * @description Whether the modal is open or not.
32
+ */
10
33
  open?: boolean | undefined;
34
+ /**
35
+ * @description Callback that is called when the modal is requested to be closed.
36
+ */
11
37
  onRequestClose?: (() => void) | undefined;
12
- renderDescription?: ((index: number) => ReactNode) | undefined;
38
+ /**
39
+ * @description Callback that renders an element to be displayed as the description of the current image.
40
+ * @param item The current item being displayed.
41
+ * @param index The index of the current item being displayed.
42
+ */
43
+ renderDescription?: ((item: SimpleImageSliderItem, index: number) => ReactNode) | undefined;
44
+ /**
45
+ * @description Item to be rendered in place of the default close button icon.
46
+ */
47
+ CloseButtonIcon?: RenderProp;
13
48
  } & React.RefAttributes<FlashList<SimpleImageSliderItem>>>;
14
49
  export default FullScreenImageSlider;
15
50
  //# sourceMappingURL=FullScreenImageSlider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FullScreenImageSlider.d.ts","sourceRoot":"","sources":["../../../src/FullScreenImageSlider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAEV,KAAK,SAAS,EAKjB,MAAM,OAAO,CAAC;AAYf,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAA4B,EACxB,KAAK,0BAA0B,EAC/B,KAAK,qBAAqB,EAC7B,MAAM,yBAAyB,CAAC;AAGjC,MAAM,MAAM,0BAA0B,GAAG,0BAA0B,GAAG;IAClE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC;CACpD,CAAC;AAqBF,QAAA,MAAM,qBAAqB;;4BAvBA,IAAI;iCACC,MAAM,KAAK,SAAS;0DA8GlD,CAAC;AAEH,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"FullScreenImageSlider.d.ts","sourceRoot":"","sources":["../../../src/FullScreenImageSlider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAEV,KAAK,SAAS,EAKjB,MAAM,OAAO,CAAC;AAWf,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAA4B,EAAE,KAAK,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAG/F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAmB,EAAE,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEjE,MAAM,MAAM,0BAA0B,GAAG,0BAA0B,GAAG;IAClE;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC;IAC9E;;OAEG;IACH,eAAe,CAAC,EAAE,UAAU,CAAC;CAChC,CAAC;AAqBF;;GAEG;AACH,QAAA,MAAM,qBAAqB;IA1CvB;;OAEG;;IAEH;;OAEG;4BACoB,IAAI;IAC3B;;;;OAIG;gCACwB,qBAAqB,SAAS,MAAM,KAAK,SAAS;IAC7E;;OAEG;sBACe,UAAU;0DAiI9B,CAAC;AAEH,eAAe,qBAAqB,CAAC"}
@@ -1,8 +1,17 @@
1
1
  import React from 'react';
2
2
  import { type StyleProp, type ViewStyle } from 'react-native';
3
3
  type PageCounterProps = {
4
+ /**
5
+ * @description The current page number (**counting from 1**).
6
+ */
4
7
  currentPage: number;
8
+ /**
9
+ * @description The total number of pages.
10
+ */
5
11
  totalPages: number;
12
+ /**
13
+ * @description Additional styles or styles to override default style of the container View.
14
+ */
6
15
  style?: StyleProp<ViewStyle>;
7
16
  };
8
17
  export default function PageCounter({ currentPage, totalPages, style }: PageCounterProps): React.JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"PageCounter.d.ts","sourceRoot":"","sources":["../../../src/PageCounter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,KAAK,SAAS,EAA0B,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAGtF,KAAK,gBAAgB,GAAG;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAChC,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,gBAAgB,qBAWvF"}
1
+ {"version":3,"file":"PageCounter.d.ts","sourceRoot":"","sources":["../../../src/PageCounter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,KAAK,SAAS,EAAQ,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAGpE,KAAK,gBAAgB,GAAG;IACpB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAChC,CAAC;AAcF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,gBAAgB,qBAQvF"}
@@ -1,18 +1,48 @@
1
1
  import React, { type PropsWithChildren } from 'react';
2
2
  import { type LayoutChangeEvent, type StyleProp, type ViewStyle } from 'react-native';
3
- import { type SharedValue } from 'react-native-reanimated';
3
+ import type { PinchToZoomStatus } from './@types/pinch-to-zoom';
4
4
  export type PinchToZoomProps = PropsWithChildren<{
5
+ /**
6
+ * @description The minimum zoom scale of the image.
7
+ * @default 1
8
+ */
5
9
  minimumZoomScale?: number;
10
+ /**
11
+ * @description The maximum zoom scale of the image.
12
+ * @default 8
13
+ */
6
14
  maximumZoomScale?: number;
15
+ /**
16
+ * @description Additional styles or styles to override default style of the container View.
17
+ */
7
18
  style?: StyleProp<ViewStyle>;
8
- onPinchStart?: () => void;
9
- onPinchEnd?: () => void;
19
+ /**
20
+ * @description Whether all gestures should be disabled or not.
21
+ * @default false
22
+ */
10
23
  disabled?: boolean;
24
+ /**
25
+ * @description Callback that is called when the layout of the container changes.
26
+ * @param {LayoutChangeEvent} e The layout change event.
27
+ */
11
28
  onLayout?: (e: LayoutChangeEvent) => void;
29
+ /**
30
+ * @description Callback that is called when the scale of the image changes to a value different from `minimumZoomScale`.
31
+ */
12
32
  onScaleChange?: () => void;
33
+ /**
34
+ * @description Callback that is called when the scale of the image changes to `minimumZoomScale`.
35
+ */
13
36
  onScaleReset?: () => void;
14
- onTranslationChange?: (x: SharedValue<number>, y: SharedValue<number>, scale: SharedValue<number>) => void;
15
- onRequestClose?: () => void;
37
+ /**
38
+ * @description Callback that is called when either the translation or the scale of the image change.
39
+ * @param {PinchToZoomStatus} status The current status.
40
+ */
41
+ onTranslationChange?: (status: PinchToZoomStatus) => void;
42
+ /**
43
+ * @description Callback that is called when gestures should lead to the item being dismissed.
44
+ */
45
+ onDismiss?: () => void;
16
46
  }>;
17
- export default function PinchToZoom({ minimumZoomScale, maximumZoomScale, style: propStyle, onPinchStart, onPinchEnd, disabled, onLayout, onTranslationChange, onScaleChange, onScaleReset, children, onRequestClose, }: PinchToZoomProps): React.JSX.Element;
47
+ export default function PinchToZoom({ minimumZoomScale, maximumZoomScale, style: propStyle, disabled, onLayout, onTranslationChange, onScaleChange, onScaleReset, children, onDismiss, }: PinchToZoomProps): React.JSX.Element;
18
48
  //# sourceMappingURL=PinchToZoom.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PinchToZoom.d.ts","sourceRoot":"","sources":["../../../src/PinchToZoom.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAwB,MAAM,OAAO,CAAC;AAC5E,OAAO,EACH,KAAK,iBAAiB,EACtB,KAAK,SAAS,EAEd,KAAK,SAAS,EACjB,MAAM,cAAc,CAAC;AACtB,OAAiB,EAGb,KAAK,WAAW,EAKnB,MAAM,yBAAyB,CAAC;AAKjC,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;IAC7C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC1C,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,mBAAmB,CAAC,EAAE,CAClB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,EACtB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,EACtB,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,KACzB,IAAI,CAAC;IACV,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;CAC/B,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAChC,gBAAoB,EACpB,gBAAoB,EACpB,KAAK,EAAE,SAAS,EAChB,YAAY,E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R,SAAS,GACZ,EAAE,gBAAgB,qBA4QlB"}
@@ -1,10 +1,22 @@
1
1
  import React from 'react';
2
2
  import { FlashList } from '@shopify/flash-list';
3
- import { type BaseSimpleImageSliderProps, type SimpleImageSliderItem } from './BaseSimpleImageSlider';
3
+ import { type BaseSimpleImageSliderProps } from './BaseSimpleImageSlider';
4
+ import type { SimpleImageSliderItem } from './@types/slider';
4
5
  export type SimpleImageSliderProps = BaseSimpleImageSliderProps & {
6
+ /**
7
+ * @description Whether the full screen mode is enabled or not. **Caution:** when this is enabled, the `onItemPress` prop will be ignored.
8
+ * @default false
9
+ */
5
10
  fullScreenEnabled?: boolean;
6
11
  };
12
+ /**
13
+ * @description A simple image slider that displays images in a list and can show a {@link FullScreenImageSlider} on press.
14
+ */
7
15
  declare const SimpleImageSlider: React.ForwardRefExoticComponent<BaseSimpleImageSliderProps & {
16
+ /**
17
+ * @description Whether the full screen mode is enabled or not. **Caution:** when this is enabled, the `onItemPress` prop will be ignored.
18
+ * @default false
19
+ */
8
20
  fullScreenEnabled?: boolean | undefined;
9
21
  } & React.RefAttributes<FlashList<SimpleImageSliderItem>>>;
10
22
  export default SimpleImageSlider;
@@ -1 +1 @@
1
- {"version":3,"file":"SimpleImageSlider.d.ts","sourceRoot":"","sources":["../../../src/SimpleImageSlider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoD,MAAM,OAAO,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGhD,OAA4B,EACxB,KAAK,0BAA0B,EAC/B,KAAK,qBAAqB,EAC7B,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,sBAAsB,GAAG,0BAA0B,GAAG;IAC9D,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC/B,CAAC;AAEF,QAAA,MAAM,iBAAiB;;0DAwDtB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"SimpleImageSlider.d.ts","sourceRoot":"","sources":["../../../src/SimpleImageSlider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoD,MAAM,OAAO,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGhD,OAA4B,EAAE,KAAK,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAC/F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,MAAM,MAAM,sBAAsB,GAAG,0BAA0B,GAAG;IAC9D;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC/B,CAAC;AAEF;;GAEG;AACH,QAAA,MAAM,iBAAiB;IAVnB;;;OAGG;;0DA+DN,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import type { IconsProps } from '../@types/icons';
3
+ declare function IconX({ size, color, stroke, ...props }: IconsProps): React.JSX.Element;
4
+ export default IconX;
5
+ //# sourceMappingURL=IconX.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IconX.d.ts","sourceRoot":"","sources":["../../../../src/icons/IconX.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,iBAAS,KAAK,CAAC,EAAE,IAAS,EAAE,KAAiB,EAAE,MAAU,EAAE,GAAG,KAAK,EAAE,EAAE,UAAU,qBAkBhF;AACD,eAAe,KAAK,CAAC"}
@@ -2,5 +2,7 @@ import StyledComponentsThemeProvider from './StyledComponentsThemeProvider';
2
2
  import BaseListImageSlider, { type BaseSimpleImageSliderProps } from './BaseSimpleImageSlider';
3
3
  import SimpleImageSlider, { type SimpleImageSliderProps } from './SimpleImageSlider';
4
4
  import FullScreenImageSlider, { type FullScreenImageSliderProps } from './FullScreenImageSlider';
5
- export { StyledComponentsThemeProvider as SimpleImageSliderThemeProvider, BaseListImageSlider, type BaseSimpleImageSliderProps, SimpleImageSlider, type SimpleImageSliderProps, FullScreenImageSlider, type FullScreenImageSliderProps, };
5
+ import PinchToZoom, { type PinchToZoomProps } from './PinchToZoom';
6
+ import type { SimpleImageSliderItem } from './@types/slider';
7
+ export { StyledComponentsThemeProvider as SimpleImageSliderThemeProvider, BaseListImageSlider, type BaseSimpleImageSliderProps, SimpleImageSlider, type SimpleImageSliderProps, FullScreenImageSlider, type FullScreenImageSliderProps, PinchToZoom, type PinchToZoomProps, type SimpleImageSliderItem, };
6
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,6BAA6B,MAAM,iCAAiC,CAAC;AAC5E,OAAO,mBAAmB,EAAE,EAAE,KAAK,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAC/F,OAAO,iBAAiB,EAAE,EAAE,KAAK,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,qBAAqB,EAAE,EAAE,KAAK,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAEjG,OAAO,EACH,6BAA6B,IAAI,8BAA8B,EAC/D,mBAAmB,EACnB,KAAK,0BAA0B,EAC/B,iBAAiB,EACjB,KAAK,sBAAsB,EAC3B,qBAAqB,EACrB,KAAK,0BAA0B,GAClC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,6BAA6B,MAAM,iCAAiC,CAAC;AAC5E,OAAO,mBAAmB,EAAE,EAAE,KAAK,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAC/F,OAAO,iBAAiB,EAAE,EAAE,KAAK,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,qBAAqB,EAAE,EAAE,KAAK,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACjG,OAAO,WAAW,EAAE,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,OAAO,EACH,6BAA6B,IAAI,8BAA8B,EAC/D,mBAAmB,EACnB,KAAK,0BAA0B,EAC/B,iBAAiB,EACjB,KAAK,sBAAsB,EAC3B,qBAAqB,EACrB,KAAK,0BAA0B,EAC/B,WAAW,EACX,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,GAC7B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@one-am/react-native-simple-image-slider",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "A simple and performant image slider made with FlashList. Includes a full screen gallery component with gesture support.",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -90,7 +90,6 @@
90
90
  "react-native-svg": "^15.1.0",
91
91
  "release-it": "^15.0.0",
92
92
  "styled-components": "^6.1.8",
93
- "tabler-icons-react-native": "^2.42.1",
94
93
  "typescript": "^5.2.2",
95
94
  "typescript-plugin-styled-components": "^3.0.0"
96
95
  },
@@ -110,9 +109,8 @@
110
109
  "react-native-gesture-handler": "^2.15.0",
111
110
  "react-native-reanimated": "~3.6.2",
112
111
  "react-native-safe-area-context": "*",
113
- "styled-components": "^6.1.8",
114
- "tabler-icons-react-native": "*",
115
- "react-native-svg": "*"
112
+ "react-native-svg": "*",
113
+ "styled-components": "^6.1.8"
116
114
  },
117
115
  "workspaces": [
118
116
  "example"
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+
3
+ export interface IconsProps extends Partial<Omit<React.SVGProps<SVGSVGElement>, 'stroke'>> {
4
+ size?: number;
5
+ stroke?: number;
6
+ }
@@ -0,0 +1,9 @@
1
+ import type { SharedValue } from 'react-native-reanimated';
2
+
3
+ export type PinchToZoomStatus = {
4
+ scale: SharedValue<number>;
5
+ translation: {
6
+ x: SharedValue<number>;
7
+ y: SharedValue<number>;
8
+ };
9
+ };
@@ -0,0 +1,5 @@
1
+ import type { ImageProps } from 'expo-image';
2
+
3
+ export type SimpleImageSliderItem = ImageProps & {
4
+ key: string;
5
+ };
@@ -14,17 +14,13 @@ import { Pressable, type StyleProp, type ViewStyle } from 'react-native';
14
14
  import type ViewToken from '@shopify/flash-list/src/viewability/ViewToken';
15
15
  import styled from 'styled-components/native';
16
16
  import PageCounter from './PageCounter';
17
- import PinchToZoom from './PinchToZoom';
18
- import { type SharedValue } from 'react-native-reanimated';
17
+ import PinchToZoom, { type PinchToZoomProps } from './PinchToZoom';
19
18
  import { GestureHandlerRootView, ScrollView } from 'react-native-gesture-handler';
20
19
  import renderProp, { type RenderProp } from './utils/renderProp';
21
-
22
- export type SimpleImageSliderItem = ImageProps & {
23
- key: string;
24
- };
20
+ import type { SimpleImageSliderItem } from './@types/slider';
25
21
 
26
22
  export type BaseSimpleImageSliderProps = {
27
- data: SimpleImageSliderItem[] | undefined;
23
+ data: SimpleImageSliderItem[];
28
24
  style?: StyleProp<ViewStyle>;
29
25
  imageWidth?: number;
30
26
  imageHeight?: number;
@@ -41,12 +37,8 @@ export type BaseSimpleImageSliderProps = {
41
37
  indexOverride?: number;
42
38
  onViewableItemChange?: (index: number) => void;
43
39
  enablePinchToZoom?: boolean;
44
- onPinchToZoomTranslationChange?: (
45
- x: SharedValue<number>,
46
- y: SharedValue<number>,
47
- scale: SharedValue<number>
48
- ) => void;
49
- onPinchToZoomRequestClose?: () => void;
40
+ onPinchToZoomStatusChange?: PinchToZoomProps['onTranslationChange'];
41
+ onPinchToZoomRequestClose?: PinchToZoomProps['onDismiss'];
50
42
  };
51
43
 
52
44
  const StyledAbsoluteComponentContainer = styled.View<{
@@ -116,6 +108,11 @@ const StyledPinchToZoom = styled(PinchToZoom)`
116
108
  z-index: 1000;
117
109
  `;
118
110
 
111
+ /**
112
+ * @description A simple image slider that displays a list of images. This is the component
113
+ * that {@link SimpleImageSlider} and {@link FullScreenImageSlider}
114
+ * are built upon. You should normally use one of those two components instead of this one.
115
+ */
119
116
  const BaseListImageSlider = forwardRef<
120
117
  FlashList<SimpleImageSliderItem>,
121
118
  BaseSimpleImageSliderProps
@@ -138,7 +135,7 @@ const BaseListImageSlider = forwardRef<
138
135
  indexOverride,
139
136
  onViewableItemChange,
140
137
  enablePinchToZoom = false,
141
- onPinchToZoomTranslationChange,
138
+ onPinchToZoomStatusChange,
142
139
  onPinchToZoomRequestClose,
143
140
  },
144
141
  ref
@@ -231,8 +228,8 @@ const BaseListImageSlider = forwardRef<
231
228
  <StyledContainer aspectRatio={imageAspectRatio} style={style}>
232
229
  {enablePinchToZoom ? (
233
230
  <StyledPinchToZoom
234
- onRequestClose={onPinchToZoomRequestClose}
235
- onTranslationChange={onPinchToZoomTranslationChange}
231
+ onDismiss={onPinchToZoomRequestClose}
232
+ onTranslationChange={onPinchToZoomStatusChange}
236
233
  onScaleChange={onScaleChange}
237
234
  onScaleReset={onScaleReset}
238
235
  maximumZoomScale={5}
@@ -7,10 +7,9 @@ import React, {
7
7
  useState,
8
8
  } from 'react';
9
9
  import { Modal, type ScaledSize, StyleSheet, useWindowDimensions } from 'react-native';
10
- import { IconX } from 'tabler-icons-react-native';
10
+ import IconX from './icons/IconX';
11
11
  import Animated, {
12
12
  runOnJS,
13
- type SharedValue,
14
13
  useAnimatedStyle,
15
14
  useSharedValue,
16
15
  withTiming,
@@ -18,21 +17,36 @@ import Animated, {
18
17
  import { setStatusBarStyle } from 'expo-status-bar';
19
18
  import styled, { type DefaultTheme, useTheme } from 'styled-components/native';
20
19
  import { FlashList } from '@shopify/flash-list';
21
- import BaseListImageSlider, {
22
- type BaseSimpleImageSliderProps,
23
- type SimpleImageSliderItem,
24
- } from './BaseSimpleImageSlider';
20
+ import BaseListImageSlider, { type BaseSimpleImageSliderProps } from './BaseSimpleImageSlider';
25
21
  import { type EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';
22
+ import type { PinchToZoomStatus } from './@types/pinch-to-zoom';
23
+ import type { SimpleImageSliderItem } from './@types/slider';
24
+ import renderProp, { type RenderProp } from './utils/renderProp';
26
25
 
27
26
  export type FullScreenImageSliderProps = BaseSimpleImageSliderProps & {
27
+ /**
28
+ * @description Whether the modal is open or not.
29
+ */
28
30
  open?: boolean;
31
+ /**
32
+ * @description Callback that is called when the modal is requested to be closed.
33
+ */
29
34
  onRequestClose?: () => void;
30
- renderDescription?: (index: number) => ReactNode;
35
+ /**
36
+ * @description Callback that renders an element to be displayed as the description of the current image.
37
+ * @param item The current item being displayed.
38
+ * @param index The index of the current item being displayed.
39
+ */
40
+ renderDescription?: (item: SimpleImageSliderItem, index: number) => ReactNode;
41
+ /**
42
+ * @description Item to be rendered in place of the default close button icon.
43
+ */
44
+ CloseButtonIcon?: RenderProp;
31
45
  };
32
46
 
33
47
  const StyledDescriptionContainer = styled.View`
34
48
  position: absolute;
35
- border-top-width: 1px;
49
+ border-top-width: ${({ theme }) => theme.styles.borderWidth.xs}px;
36
50
  border-top-color: ${({ theme }) => theme.colors.descriptionContainerBorder};
37
51
  width: 100%;
38
52
  padding-top: ${({ theme }) => theme.styles.spacing.l}px;
@@ -49,11 +63,22 @@ const StyledModalContentContainer = styled(Animated.View)`
49
63
  gap: ${({ theme }) => theme.styles.spacing.m}px;
50
64
  `;
51
65
 
66
+ /**
67
+ * @description A full screen image slider that displays images in a modal.
68
+ */
52
69
  const FullScreenImageSlider = forwardRef<
53
70
  FlashList<SimpleImageSliderItem>,
54
71
  FullScreenImageSliderProps
55
72
  >(function FullScreenImageSlider(
56
- { open, onRequestClose, renderDescription, onViewableItemChange, ...props },
73
+ {
74
+ CloseButtonIcon,
75
+ open,
76
+ onRequestClose,
77
+ renderDescription,
78
+ onViewableItemChange,
79
+ data,
80
+ ...props
81
+ },
57
82
  ref
58
83
  ) {
59
84
  const windowDimensions = useWindowDimensions();
@@ -90,10 +115,10 @@ const FullScreenImageSlider = forwardRef<
90
115
  };
91
116
  }, []);
92
117
 
93
- const onPinchToZoomTranslationChange = useCallback(
94
- (x: SharedValue<number>, y: SharedValue<number>, scale: SharedValue<number>) => {
118
+ const onPinchToZoomStatusChange = useCallback(
119
+ ({ translation, scale }: PinchToZoomStatus) => {
95
120
  if (scale.value <= 1) {
96
- if (x.value === 0 && y.value === 0) {
121
+ if (translation.x.value === 0 && translation.y.value === 0) {
97
122
  runOnJS(setStatusBarStyle)('light');
98
123
  backgroundOpacity.value = withTiming(1);
99
124
  } else {
@@ -116,11 +141,16 @@ const FullScreenImageSlider = forwardRef<
116
141
  >
117
142
  <StyledModalContentContainer style={[styles.modalContent, modalContentStyle]}>
118
143
  <StyledModalCloseButton style={styles.closeButton} onPress={onRequestClose}>
119
- <IconX color={theme.colors.fullScreenCloseButton} />
144
+ {CloseButtonIcon ? (
145
+ renderProp(CloseButtonIcon)
146
+ ) : (
147
+ <IconX color={theme.colors.fullScreenCloseButton} />
148
+ )}
120
149
  </StyledModalCloseButton>
121
150
  <BaseListImageSlider
151
+ data={data}
122
152
  enablePinchToZoom={true}
123
- onPinchToZoomTranslationChange={onPinchToZoomTranslationChange}
153
+ onPinchToZoomStatusChange={onPinchToZoomStatusChange}
124
154
  onPinchToZoomRequestClose={onRequestClose}
125
155
  {...props}
126
156
  onViewableItemChange={internalOnViewableItemChange}
@@ -129,9 +159,12 @@ const FullScreenImageSlider = forwardRef<
129
159
  ref={ref}
130
160
  />
131
161
 
132
- {renderDescription ? (
162
+ {renderDescription && data[internalIndex] ? (
133
163
  <StyledDescriptionContainer style={styles.descriptionContainer}>
134
- {renderDescription(internalIndex)}
164
+ {renderDescription(
165
+ data[internalIndex] as SimpleImageSliderItem,
166
+ internalIndex
167
+ )}
135
168
  </StyledDescriptionContainer>
136
169
  ) : null}
137
170
  </StyledModalContentContainer>
@@ -1,39 +1,40 @@
1
- import React, { useMemo } from 'react';
2
- import { type StyleProp, StyleSheet, Text, View, type ViewStyle } from 'react-native';
3
- import { type DefaultTheme, useTheme } from 'styled-components/native';
1
+ import React from 'react';
2
+ import { type StyleProp, Text, type ViewStyle } from 'react-native';
3
+ import styled from 'styled-components/native';
4
4
 
5
5
  type PageCounterProps = {
6
+ /**
7
+ * @description The current page number (**counting from 1**).
8
+ */
6
9
  currentPage: number;
10
+ /**
11
+ * @description The total number of pages.
12
+ */
7
13
  totalPages: number;
14
+ /**
15
+ * @description Additional styles or styles to override default style of the container View.
16
+ */
8
17
  style?: StyleProp<ViewStyle>;
9
18
  };
10
19
 
11
- export default function PageCounter({ currentPage, totalPages, style }: PageCounterProps) {
12
- const theme = useTheme();
13
- const styles = useMemo(() => makeStyles(theme), [theme]);
20
+ const StyledContainer = styled.View`
21
+ background-color: ${({ theme }) => theme.colors.pageCounterBackground};
22
+ border-width: ${({ theme }) => theme.styles.borderWidth.xs}px;
23
+ border-color: ${({ theme }) => theme.colors.pageCounterBorder};
24
+ border-radius: ${({ theme }) => theme.styles.borderRadius.m}px;
25
+ padding: ${({ theme }) => `${theme.styles.spacing.s}px ${theme.styles.spacing.s}px`};
26
+ width: 75px;
27
+ flex-direction: row;
28
+ align-items: center;
29
+ justify-content: center;
30
+ `;
14
31
 
32
+ export default function PageCounter({ currentPage, totalPages, style }: PageCounterProps) {
15
33
  return (
16
- <View style={[styles.container, style]}>
34
+ <StyledContainer style={style}>
17
35
  <Text>
18
36
  {currentPage} / {totalPages}
19
37
  </Text>
20
- </View>
38
+ </StyledContainer>
21
39
  );
22
40
  }
23
-
24
- const makeStyles = (theme: DefaultTheme) => {
25
- return StyleSheet.create({
26
- container: {
27
- backgroundColor: theme.colors.pageCounterBackground,
28
- borderWidth: 1,
29
- borderColor: theme.colors.pageCounterBorder,
30
- borderRadius: 8,
31
- paddingHorizontal: 5,
32
- paddingVertical: 6,
33
- width: 75,
34
- flexDirection: 'row',
35
- alignItems: 'center',
36
- justifyContent: 'center',
37
- },
38
- });
39
- };