@codeleap/mobile 5.0.10 → 5.0.11

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.
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { PageProps } from './types';
3
+ type PagerItemComponentProps = PageProps<any> & {
4
+ renderItem: (props: any) => JSX.Element;
5
+ };
6
+ export declare const PagerItem: import("react").NamedExoticComponent<PagerItemComponentProps>;
7
+ export {};
@@ -0,0 +1,12 @@
1
+ import { memoBy } from '@codeleap/utils';
2
+ import { TypeGuards } from '@codeleap/types';
3
+ function PagerItemComponent(props) {
4
+ const { item, renderItem: RenderItem, ...info } = props;
5
+ if (TypeGuards.isFunction(item)) {
6
+ const ItemComponent = item;
7
+ return <ItemComponent {...info}/>;
8
+ }
9
+ return <RenderItem {...info} item={item}/>;
10
+ }
11
+ export const PagerItem = memoBy(PagerItemComponent, ['renderItem', 'item']);
12
+ //# sourceMappingURL=PagerItem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PagerItem.js","sourceRoot":"","sources":["../../../src/components/Pager/PagerItem.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAExC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAM5C,SAAS,kBAAkB,CAAC,KAA8B;IACxD,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAA;IAEvD,IAAI,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAC/B,MAAM,aAAa,GAAG,IAAI,CAAA;QAC1B,OAAO,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,EAAG,CAAA;KACnC;IAED,OAAO,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAG,CAAA;AAC7C,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,kBAAkB,EAAE,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAA"}
@@ -1,58 +1,64 @@
1
- import React, { useCallback, useRef, useState } from 'react';
1
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
2
2
  import { ReduceMotion } from 'react-native-reanimated';
3
3
  import Carousel from 'react-native-reanimated-carousel';
4
4
  import { Dimensions } from 'react-native';
5
- import { TypeGuards } from '@codeleap/types';
6
- import { onUpdate, useConditionalState } from '@codeleap/hooks';
5
+ import { useConditionalState } from '@codeleap/hooks';
7
6
  import { useNestedStylesByKey } from '@codeleap/styles';
8
7
  import { useStylesFor } from '../../hooks';
9
8
  import { MobileStyleRegistry } from '../../Registry';
10
9
  import { View } from '../View';
11
10
  import { PagerDots } from './PagerDots';
11
+ import { PagerItem } from './PagerItem';
12
12
  export * from './styles';
13
13
  export * from './types';
14
14
  export * from './PagerDots';
15
- const window = Dimensions.get('window');
15
+ const window = Dimensions.get('screen');
16
16
  export function Pager(props) {
17
- const { pages, page, onChangePage, initialPage, style, showDots, renderItem: RenderItem, footer, width: carouselWidth, height: carouselHeight, autoCalculateFooterHeight, ...rest } = {
17
+ const { pages, page, onChangePage, initialPage, style, showDots, renderItem, footer, width: carouselWidth, height: carouselHeight, autoCalculateFooterHeight, removeFixedHeight, removeFixedWidth, ...rest } = {
18
18
  ...Pager.defaultProps,
19
19
  ...props,
20
20
  };
21
- const [currentPage, setCurrentPage] = useConditionalState(page, onChangePage, { initialValue: initialPage });
22
21
  const carouselRef = useRef(null);
22
+ const [currentPage, setCurrentPage] = useConditionalState(page, onChangePage, { initialValue: initialPage });
23
23
  const [footerHeight, setFooterHeight] = useState(0);
24
+ const [loaded, setLoaded] = useState(!showDots && !footer ? true : false);
24
25
  const styles = useStylesFor(Pager.styleRegistryName, style);
25
26
  const dotStyles = useNestedStylesByKey('dot', styles);
26
- onUpdate(() => {
27
- carouselRef.current?.scrollTo({ index: currentPage, animated: true });
27
+ useEffect(() => {
28
+ if (carouselRef.current?.getCurrentIndex?.() !== currentPage) {
29
+ carouselRef.current?.scrollTo?.({ index: currentPage, animated: true });
30
+ }
28
31
  }, [currentPage]);
29
- const renderItem = useCallback(({ item, index, animationValue }) => {
30
- const itemProps = {
32
+ const getItemInfo = useCallback((index) => {
33
+ const info = {
31
34
  isFirst: index === 0,
32
35
  isLast: index === pages?.length - 1,
33
36
  isOnly: pages?.length === 1,
34
- isActive: index === currentPage,
35
- isNext: index === currentPage + 1,
36
- isPrevious: index === currentPage - 1,
37
37
  index,
38
- animationValue,
39
38
  };
40
- if (TypeGuards.isFunction(item)) {
41
- const ItemComponent = item;
42
- return <ItemComponent {...itemProps}/>;
43
- }
44
- return <RenderItem {...itemProps} item={item}/>;
45
- }, [RenderItem, pages?.length, currentPage]);
46
- return (<View style={styles.wrapper}>
47
- <Carousel data={pages} withAnimation={{
39
+ return info;
40
+ }, []);
41
+ const customRenderItem = useCallback(({ item, index, animationValue }) => {
42
+ const info = getItemInfo(index);
43
+ return (<PagerItem {...info} renderItem={renderItem} item={item} animationValue={animationValue}/>);
44
+ }, [renderItem, getItemInfo]);
45
+ const onFooterLayout = useCallback((event) => {
46
+ setFooterHeight(event.nativeEvent.layout.height);
47
+ setTimeout(() => setLoaded(true), 0);
48
+ }, []);
49
+ const width = carouselWidth - removeFixedWidth;
50
+ const height = carouselHeight - ((autoCalculateFooterHeight ? footerHeight : 0) + removeFixedHeight);
51
+ return (<View style={[{ width, opacity: !loaded ? 0 : 1 }, styles.wrapper]}>
52
+ <Carousel data={pages} autoPlay={false} loop={false} overscrollEnabled={false} pagingEnabled={false} ref={carouselRef} defaultIndex={initialPage} onSnapToItem={setCurrentPage} maxScrollDistancePerSwipe={carouselWidth} minScrollDistancePerSwipe={carouselWidth * 0.1} width={width} height={height} renderItem={customRenderItem} withAnimation={{
48
53
  type: 'timing',
49
54
  config: {
50
55
  reduceMotion: ReduceMotion.Never,
51
56
  },
52
- }} autoPlay={false} ref={carouselRef} loop={false} defaultIndex={initialPage} onSnapToItem={setCurrentPage} maxScrollDistancePerSwipe={carouselWidth} width={carouselWidth} height={carouselHeight - (autoCalculateFooterHeight ? footerHeight : 0)} renderItem={renderItem} {...rest} style={styles.carousel}/>
57
+ }} {...rest} style={styles.carousel}/>
58
+
59
+ <View onLayout={onFooterLayout} style={styles.footerWrapper}>
60
+ {footer}
53
61
 
54
- <View onLayout={(event) => setFooterHeight(event.nativeEvent.layout.height)} style={styles.footerWrapper}>
55
- {/* {footer} */}
56
62
  {showDots ? (<PagerDots currentPage={currentPage} pages={pages} setCurrentPage={setCurrentPage} styles={dotStyles}/>) : null}
57
63
  </View>
58
64
  </View>);
@@ -69,6 +75,9 @@ Pager.defaultProps = {
69
75
  showDots: true,
70
76
  autoCalculateFooterHeight: true,
71
77
  initialPage: 0,
78
+ footer: null,
79
+ removeFixedHeight: 0,
80
+ removeFixedWidth: 0,
72
81
  };
73
82
  MobileStyleRegistry.registerComponent(Pager);
74
83
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Pager/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACtD,OAAO,QAA+B,MAAM,kCAAkC,CAAA;AAE9E,OAAO,EAAE,UAAU,EAAqB,MAAM,cAAc,CAAA;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAC/D,OAAO,EAAyC,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAC9F,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAA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WAAW,EAAE,CAAC;IACd,MAAM,EAAE,IAAI;IACZ,iBAAiB,EAAE,CAAC;IACpB,gBAAgB,EAAE,CAAC;CACY,CAAA;AAEjC,mBAAmB,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAA"}
@@ -6,11 +6,8 @@ import { CarouselRenderItemInfo } from 'react-native-reanimated-carousel/lib/typ
6
6
  export type PageProps<T> = CarouselRenderItemInfo<T> & {
7
7
  isLast: boolean;
8
8
  isFirst: boolean;
9
- isActive: boolean;
10
9
  isOnly: boolean;
11
- isNext: boolean;
12
10
  index: number;
13
- isPrevious: boolean;
14
11
  };
15
12
  export type PagerProps<T> = Partial<Omit<TCarouselProps<T>, 'data' | 'renderItem'>> & {
16
13
  pages: TCarouselProps<T>['data'];
@@ -22,4 +19,6 @@ export type PagerProps<T> = Partial<Omit<TCarouselProps<T>, 'data' | 'renderItem
22
19
  showDots?: boolean;
23
20
  footer?: ReactNode;
24
21
  autoCalculateFooterHeight?: boolean;
22
+ removeFixedHeight?: number;
23
+ removeFixedWidth?: number;
25
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/mobile",
3
- "version": "5.0.10",
3
+ "version": "5.0.11",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -9,39 +9,39 @@
9
9
  "directory": "packages/mobile"
10
10
  },
11
11
  "devDependencies": {
12
- "@codeleap/types": "5.0.10",
13
- "@codeleap/utils": "5.0.10",
14
- "@codeleap/hooks": "5.0.10",
15
- "@codeleap/form": "5.0.10",
16
- "@codeleap/query": "5.0.10",
17
- "@codeleap/logger": "5.0.10",
18
- "@codeleap/config": "5.0.10",
19
- "@codeleap/modals": "5.0.10"
12
+ "@codeleap/types": "5.0.11",
13
+ "@codeleap/utils": "5.0.11",
14
+ "@codeleap/hooks": "5.0.11",
15
+ "@codeleap/form": "5.0.11",
16
+ "@codeleap/query": "5.0.11",
17
+ "@codeleap/logger": "5.0.11",
18
+ "@codeleap/config": "5.0.11",
19
+ "@codeleap/modals": "5.0.11"
20
20
  },
21
21
  "scripts": {
22
22
  "build": "tsc --build",
23
23
  "lint": "eslint -c .eslintrc.js --fix \"./src/**/*.{ts,tsx,js,jsx}\""
24
24
  },
25
25
  "peerDependencies": {
26
- "@codeleap/types": "5.0.10",
27
- "@codeleap/utils": "5.0.10",
28
- "@codeleap/hooks": "5.0.10",
29
- "@codeleap/form": "5.0.10",
30
- "@codeleap/query": "5.0.10",
31
- "@codeleap/logger": "5.0.10",
32
- "@codeleap/styles": "5.0.10",
33
- "@codeleap/modals": "5.0.10",
34
- "@d11/react-native-fast-image": "8.8.0",
35
- "@react-native-firebase/messaging": "21.7.2",
36
- "@react-navigation/bottom-tabs": "7.2.0",
37
- "@react-navigation/native": "7.0.14",
38
- "@react-navigation/native-stack": "7.2.0",
26
+ "@codeleap/types": "5.0.11",
27
+ "@codeleap/utils": "5.0.11",
28
+ "@codeleap/hooks": "5.0.11",
29
+ "@codeleap/form": "5.0.11",
30
+ "@codeleap/query": "5.0.11",
31
+ "@codeleap/logger": "5.0.11",
32
+ "@codeleap/styles": "5.0.11",
33
+ "@codeleap/modals": "5.0.11",
34
+ "@d11/react-native-fast-image": "8.9.2",
35
+ "@react-native-firebase/messaging": "21.12.0",
36
+ "@react-navigation/bottom-tabs": "7.3.1",
37
+ "@react-navigation/native": "7.0.17",
38
+ "@react-navigation/native-stack": "7.3.1",
39
39
  "react": "18.2.0",
40
- "react-native": "0.77.0",
40
+ "react-native": "0.77.1",
41
41
  "react-native-calendars": "1.1307.0",
42
- "react-native-date-picker": "5.0.9",
42
+ "react-native-date-picker": "5.0.10",
43
43
  "react-native-device-info": "14.0.4",
44
- "react-native-gesture-handler": "2.22.1",
44
+ "react-native-gesture-handler": "2.24.0",
45
45
  "react-native-image-crop-picker": "0.42.0",
46
46
  "react-native-image-viewing": "0.2.2",
47
47
  "react-native-localize": "3.4.1",
@@ -54,8 +54,8 @@
54
54
  "@miblanchard/react-native-slider": "2.3.1",
55
55
  "react-native-currency-input": "^1.1.1",
56
56
  "react-native-masked-text": "1.13.0",
57
- "react-native-reanimated-carousel": "^3.5.1",
58
- "react-native-sortables": "^1.1.1",
57
+ "react-native-reanimated-carousel": "4.0.2",
58
+ "react-native-sortables": "1.1.1",
59
59
  "react-native-uuid": "2.0.1"
60
60
  }
61
61
  }
package/package.json.bak CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/mobile",
3
- "version": "5.0.10",
3
+ "version": "5.0.11",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -31,17 +31,17 @@
31
31
  "@codeleap/logger": "workspace:*",
32
32
  "@codeleap/styles": "workspace:*",
33
33
  "@codeleap/modals": "workspace:*",
34
- "@d11/react-native-fast-image": "8.8.0",
35
- "@react-native-firebase/messaging": "21.7.2",
36
- "@react-navigation/bottom-tabs": "7.2.0",
37
- "@react-navigation/native": "7.0.14",
38
- "@react-navigation/native-stack": "7.2.0",
34
+ "@d11/react-native-fast-image": "8.9.2",
35
+ "@react-native-firebase/messaging": "21.12.0",
36
+ "@react-navigation/bottom-tabs": "7.3.1",
37
+ "@react-navigation/native": "7.0.17",
38
+ "@react-navigation/native-stack": "7.3.1",
39
39
  "react": "18.2.0",
40
- "react-native": "0.77.0",
40
+ "react-native": "0.77.1",
41
41
  "react-native-calendars": "1.1307.0",
42
- "react-native-date-picker": "5.0.9",
42
+ "react-native-date-picker": "5.0.10",
43
43
  "react-native-device-info": "14.0.4",
44
- "react-native-gesture-handler": "2.22.1",
44
+ "react-native-gesture-handler": "2.24.0",
45
45
  "react-native-image-crop-picker": "0.42.0",
46
46
  "react-native-image-viewing": "0.2.2",
47
47
  "react-native-localize": "3.4.1",
@@ -54,8 +54,8 @@
54
54
  "@miblanchard/react-native-slider": "2.3.1",
55
55
  "react-native-currency-input": "^1.1.1",
56
56
  "react-native-masked-text": "1.13.0",
57
- "react-native-reanimated-carousel": "^3.5.1",
58
- "react-native-sortables": "^1.1.1",
57
+ "react-native-reanimated-carousel": "4.0.2",
58
+ "react-native-sortables": "1.1.1",
59
59
  "react-native-uuid": "2.0.1"
60
60
  }
61
61
  }
@@ -0,0 +1,20 @@
1
+ import { memoBy } from '@codeleap/utils'
2
+ import { PageProps } from './types'
3
+ import { TypeGuards } from '@codeleap/types'
4
+
5
+ type PagerItemComponentProps = PageProps<any> & {
6
+ renderItem: (props: any) => JSX.Element
7
+ }
8
+
9
+ function PagerItemComponent(props: PagerItemComponentProps) {
10
+ const { item, renderItem: RenderItem, ...info } = props
11
+
12
+ if (TypeGuards.isFunction(item)) {
13
+ const ItemComponent = item
14
+ return <ItemComponent {...info} />
15
+ }
16
+
17
+ return <RenderItem {...info} item={item} />
18
+ }
19
+
20
+ export const PagerItem = memoBy(PagerItemComponent, ['renderItem', 'item'])
@@ -1,22 +1,22 @@
1
- import React, { useCallback, useRef, useState } from 'react'
1
+ import React, { useCallback, useEffect, useRef, useState } from 'react'
2
2
  import { ReduceMotion } from 'react-native-reanimated'
3
3
  import Carousel, { ICarouselInstance } from 'react-native-reanimated-carousel'
4
4
  import { CarouselRenderItemInfo, TCarouselProps } from 'react-native-reanimated-carousel/lib/typescript/types'
5
5
  import { Dimensions, LayoutChangeEvent } from 'react-native'
6
- import { TypeGuards } from '@codeleap/types'
7
- import { onUpdate, useConditionalState } from '@codeleap/hooks'
6
+ import { useConditionalState } from '@codeleap/hooks'
8
7
  import { AnyRecord, IJSX, StyledComponentProps, useNestedStylesByKey } from '@codeleap/styles'
9
8
  import { useStylesFor } from '../../hooks'
10
9
  import { MobileStyleRegistry } from '../../Registry'
11
10
  import { View } from '../View'
12
11
  import { PageProps, PagerProps } from './types'
13
12
  import { PagerDots } from './PagerDots'
13
+ import { PagerItem } from './PagerItem'
14
14
 
15
15
  export * from './styles'
16
16
  export * from './types'
17
17
  export * from './PagerDots'
18
18
 
19
- const window = Dimensions.get('window')
19
+ const window = Dimensions.get('screen')
20
20
 
21
21
  export function Pager<T>(props: PagerProps<T>) {
22
22
  const {
@@ -26,73 +26,95 @@ export function Pager<T>(props: PagerProps<T>) {
26
26
  initialPage,
27
27
  style,
28
28
  showDots,
29
- renderItem: RenderItem,
29
+ renderItem,
30
30
  footer,
31
31
  width: carouselWidth,
32
32
  height: carouselHeight,
33
33
  autoCalculateFooterHeight,
34
+ removeFixedHeight,
35
+ removeFixedWidth,
34
36
  ...rest
35
37
  } = {
36
38
  ...Pager.defaultProps,
37
39
  ...props,
38
40
  }
39
41
 
40
- const [currentPage, setCurrentPage] = useConditionalState(page, onChangePage, { initialValue: initialPage })
41
42
  const carouselRef = useRef<ICarouselInstance>(null)
43
+
44
+ const [currentPage, setCurrentPage] = useConditionalState(page, onChangePage, { initialValue: initialPage })
42
45
  const [footerHeight, setFooterHeight] = useState(0)
46
+ const [loaded, setLoaded] = useState(!showDots && !footer ? true : false)
43
47
 
44
48
  const styles = useStylesFor(Pager.styleRegistryName, style)
45
49
  const dotStyles = useNestedStylesByKey('dot', styles)
46
50
 
47
- onUpdate(() => {
48
- carouselRef.current?.scrollTo({ index: currentPage, animated: true })
51
+ useEffect(() => {
52
+ if (carouselRef.current?.getCurrentIndex?.() !== currentPage) {
53
+ carouselRef.current?.scrollTo?.({ index: currentPage, animated: true })
54
+ }
49
55
  }, [currentPage])
50
56
 
51
- const renderItem = useCallback(({ item, index, animationValue }: CarouselRenderItemInfo<any>) => {
52
- const itemProps: Omit<PageProps<T>, 'item'> = {
57
+ const getItemInfo = useCallback((index: number) => {
58
+ const info: Omit<PageProps<T>, 'item' | 'animationValue'> = {
53
59
  isFirst: index === 0,
54
60
  isLast: index === pages?.length - 1,
55
61
  isOnly: pages?.length === 1,
56
- isActive: index === currentPage,
57
- isNext: index === currentPage + 1,
58
- isPrevious: index === currentPage - 1,
59
62
  index,
60
- animationValue,
61
63
  }
62
64
 
63
- if (TypeGuards.isFunction(item)) {
64
- const ItemComponent = item
65
- return <ItemComponent {...itemProps} />
66
- }
65
+ return info
66
+ }, [])
67
+
68
+ const customRenderItem = useCallback(({ item, index, animationValue }: CarouselRenderItemInfo<any>) => {
69
+ const info = getItemInfo(index)
67
70
 
68
- return <RenderItem {...itemProps} item={item} />
69
- }, [RenderItem, pages?.length, currentPage])
71
+ return (
72
+ <PagerItem
73
+ {...info}
74
+ renderItem={renderItem}
75
+ item={item}
76
+ animationValue={animationValue}
77
+ />
78
+ )
79
+ }, [renderItem, getItemInfo])
80
+
81
+ const onFooterLayout = useCallback((event: LayoutChangeEvent) => {
82
+ setFooterHeight(event.nativeEvent.layout.height)
83
+ setTimeout(() => setLoaded(true), 0)
84
+ }, [])
85
+
86
+ const width = carouselWidth - removeFixedWidth
87
+ const height = carouselHeight - ((autoCalculateFooterHeight ? footerHeight : 0) + removeFixedHeight)
70
88
 
71
89
  return (
72
- <View style={styles.wrapper}>
90
+ <View style={[{ width, opacity: !loaded ? 0 : 1 }, styles.wrapper]}>
73
91
  <Carousel
74
92
  data={pages}
93
+ autoPlay={false}
94
+ loop={false}
95
+ overscrollEnabled={false}
96
+ pagingEnabled={false}
97
+ ref={carouselRef}
98
+ defaultIndex={initialPage}
99
+ onSnapToItem={setCurrentPage}
100
+ maxScrollDistancePerSwipe={carouselWidth}
101
+ minScrollDistancePerSwipe={carouselWidth * 0.1}
102
+ width={width}
103
+ height={height}
104
+ renderItem={customRenderItem}
75
105
  withAnimation={{
76
106
  type: 'timing',
77
107
  config: {
78
108
  reduceMotion: ReduceMotion.Never,
79
109
  },
80
110
  }}
81
- autoPlay={false}
82
- ref={carouselRef}
83
- loop={false}
84
- defaultIndex={initialPage}
85
- onSnapToItem={setCurrentPage}
86
- maxScrollDistancePerSwipe={carouselWidth}
87
- width={carouselWidth}
88
- height={carouselHeight - (autoCalculateFooterHeight ? footerHeight : 0)}
89
- renderItem={renderItem}
90
111
  {...rest as TCarouselProps<T>}
91
112
  style={styles.carousel}
92
113
  />
93
114
 
94
- <View onLayout={(event: LayoutChangeEvent) => setFooterHeight(event.nativeEvent.layout.height)} style={styles.footerWrapper}>
95
- {/* {footer} */}
115
+ <View onLayout={onFooterLayout} style={styles.footerWrapper}>
116
+ {footer}
117
+
96
118
  {showDots ? (
97
119
  <PagerDots currentPage={currentPage} pages={pages} setCurrentPage={setCurrentPage} styles={dotStyles} />
98
120
  ) : null}
@@ -115,6 +137,9 @@ Pager.defaultProps = {
115
137
  showDots: true,
116
138
  autoCalculateFooterHeight: true,
117
139
  initialPage: 0,
140
+ footer: null,
141
+ removeFixedHeight: 0,
142
+ removeFixedWidth: 0,
118
143
  } as Partial<PagerProps<unknown>>
119
144
 
120
145
  MobileStyleRegistry.registerComponent(Pager)
@@ -7,11 +7,8 @@ import { CarouselRenderItemInfo } from 'react-native-reanimated-carousel/lib/typ
7
7
  export type PageProps<T> = CarouselRenderItemInfo<T> & {
8
8
  isLast: boolean
9
9
  isFirst: boolean
10
- isActive: boolean
11
10
  isOnly: boolean
12
- isNext: boolean
13
11
  index: number
14
- isPrevious: boolean
15
12
  }
16
13
 
17
14
  export type PagerProps<T> = Partial<Omit<TCarouselProps<T>, 'data' | 'renderItem'>> & {
@@ -24,4 +21,6 @@ export type PagerProps<T> = Partial<Omit<TCarouselProps<T>, 'data' | 'renderItem
24
21
  showDots?: boolean
25
22
  footer?: ReactNode
26
23
  autoCalculateFooterHeight?: boolean
24
+ removeFixedHeight?: number
25
+ removeFixedWidth?: number
27
26
  }