Skip to content

Commit 8ee0c0c

Browse files
Merge pull request #27 from RichardRNStudio/feat/26
feat(#26): add limitToSlide new property to change the limit of swipe animation
2 parents c90fb68 + bfaff6a commit 8ee0c0c

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ The package includes two render options. Besides the `default render` when you c
117117
| `showStatusBar` | boolean | false | Show status bar on top of screen. You can make your own status bar outside of this component |
118118
| `statusBarColor` | <a href="https://reactnative.dev/docs/colors">color</a>| #febe29 | Background color of status bar |
119119
| `renderStatusBar` | function | Default status bar renderer | Use to supply your own status bar component |
120+
| `limitToSlide` | number | (Device max width) * 0.35 | Use to change the limit of the slide animation. It is calculated based on the <a href="https://reactnative.dev/docs/panresponder">PanResponder's `gestureState.dx`</a> property. For example, your device's width: 400px, the limit is 400 * 0.35 = 140px, so you need to swipe at least 140px to left or right to reach the next slide in the row.
120121

121122
<h2>Examples</h2>
122123
<ul>

src/components/SliderProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const SliderProvider = (props: ISliderProviderProps) => {
6666
useCustomBackHandlerEffect,
6767
isCustomRender,
6868
data,
69+
limitToSlide,
6970
} = props;
7071
const numberOfSlides = isCustomRender
7172
? props?.numberOfSlides
@@ -233,7 +234,6 @@ const SliderProvider = (props: ISliderProviderProps) => {
233234
return true;
234235
};
235236

236-
const limitToSlide = deviceMaxWidth * 0.5;
237237
const slidesMaxWidth = (numberOfSlides - 1) * deviceMaxWidth;
238238
const navContainerMaxSize = deviceMaxWidth * navContainerMaxSizePercent;
239239
const buttonsMaxSize = (deviceMaxWidth - navContainerMaxSize) / 2 - 1;

src/defaultProps.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React from 'react';
2-
import type { ColorValue } from 'react-native';
2+
import { Dimensions, type ColorValue } from 'react-native';
33
import Button from './components/Button';
44
import StatusBarContainer from './components/StatusBarContainer';
55
import type { ISliderIntro } from './interfaces/ISliderIntro.interface';
66

7+
const deviceMaxWidth = Dimensions.get('window').width;
8+
79
const defaultProps: ISliderIntro = {
810
data: [],
911
children: null,
@@ -43,6 +45,7 @@ const defaultProps: ISliderIntro = {
4345
renderStatusBar: (backgroundColor: ColorValue) => (
4446
<StatusBarContainer backgroundColor={backgroundColor} />
4547
),
48+
limitToSlide: deviceMaxWidth * 0.35,
4649
};
4750

4851
export default defaultProps;

src/interfaces/ISliderIntro.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@ export interface ISliderIntro {
6767
showStatusBar: boolean;
6868
statusBarColor: ColorValue;
6969
renderStatusBar: (backgroundColor: ColorValue) => React.ReactNode;
70+
limitToSlide: number;
7071
}

0 commit comments

Comments
 (0)