Compare commits

..

73 Commits

Author SHA1 Message Date
greenkeeper[bot]
1f325e9abb
chore(package): update standard to version 14.2.0
Closes #1044
2019-09-11 19:27:49 +00:00
Tobias Cornille
72c6430393 Add missing scrollTo TypeScript definition (#1036) 2019-08-13 16:14:28 +08:00
Yidong Li
f00abfb859
feat(vertical): partical support vertical scrolling (#1017) 2019-07-16 21:44:46 +08:00
Yidong Li
2cda5bda31
fix(children): fix the crash when only one children (#1016) 2019-07-15 15:25:00 +08:00
greenkeeper[bot]
44cbed20bd chore(package): update standard to version 13.0.1 (#1014) 2019-07-12 11:50:55 +08:00
Yidong Li
9b527b22ab
fix(types): allow the style to be array (#1013)
fix #543
2019-07-10 22:11:18 +08:00
Yidong Li
988e2c010c
docs(nightly): add nightly version updates (#1012) 2019-07-10 21:01:55 +08:00
Yidong Li
f8d66f30c2
feat(pages): support optionally render page (#1009)
* feat(pages): support optionally render page

re #1004

* fix(ScrollView): android ScrollView will not scrollTo certain offset when props change
2019-07-09 16:12:04 +08:00
斯人
655eb204e1
Merge pull request #1006 from leecade/dependabot/npm_and_yarn/examples/handlebars-4.1.2
Bump handlebars from 4.0.10 to 4.1.2 in /examples
2019-07-05 02:43:05 +08:00
dependabot[bot]
05bb025469
Bump handlebars from 4.0.10 to 4.1.2 in /examples
Bumps [handlebars](https://github.com/wycats/handlebars.js) from 4.0.10 to 4.1.2.
- [Release notes](https://github.com/wycats/handlebars.js/releases)
- [Changelog](https://github.com/wycats/handlebars.js/blob/master/release-notes.md)
- [Commits](https://github.com/wycats/handlebars.js/compare/v4.0.10...v4.1.2)

Signed-off-by: dependabot[bot] <support@github.com>
2019-07-04 15:45:18 +00:00
dependabot[bot]
0676c84401 Bump stringstream from 0.0.5 to 0.0.6 in /examples (#994)
Bumps [stringstream](https://github.com/mhart/StringStream) from 0.0.5 to 0.0.6.
- [Release notes](https://github.com/mhart/StringStream/releases)
- [Commits](https://github.com/mhart/StringStream/compare/v0.0.5...v0.0.6)

Signed-off-by: dependabot[bot] <support@github.com>
2019-06-27 16:56:36 +08:00
Jong Eun Lee
7ebd74d4bd add array to dotStyles propTypes (#598) 2019-06-27 16:35:49 +08:00
dependabot[bot]
7ee508a291 Bump diff from 3.3.0 to 3.5.0 in /examples (#990)
Bumps [diff](https://github.com/kpdecker/jsdiff) from 3.3.0 to 3.5.0.
- [Release notes](https://github.com/kpdecker/jsdiff/releases)
- [Changelog](https://github.com/kpdecker/jsdiff/blob/master/release-notes.md)
- [Commits](https://github.com/kpdecker/jsdiff/compare/v3.3.0...v3.5.0)

Signed-off-by: dependabot[bot] <support@github.com>
2019-06-27 16:17:44 +08:00
greenkeeper[bot]
9a6200bd20 chore(package): update snazzy to version 7.1.0 (#736) 2019-06-27 16:07:43 +08:00
greenkeeper[bot]
057032940c chore(package): update standard to version 11.0.0 (#733) 2019-06-27 16:04:51 +08:00
Cesar Salazar
fa52596712 Added prop to disable the PrevButton (#749) 2019-06-27 15:31:22 +08:00
Yidong Li
0e850fbf6d
Merge pull request #1002 from leecade/develop
fix(autoplay): replay when autoplay is setted to true
2019-06-27 13:49:00 +08:00
李宜东
a4c06c5cdc fix(autoplay): replay when autoplay is setted to true 2019-06-27 13:42:39 +08:00
Yidong Li
c90de7b40f
Merge pull request #717 from guodf/master
fix #623
2019-06-26 21:21:53 +08:00
Yidong Li
c99f80a3d9
Merge pull request #939 from deepakaggarwal7/master
Update index.js
2019-06-26 20:31:29 +08:00
Yidong Li
aa1e9df982
Merge branch 'master' into master 2019-06-26 20:28:51 +08:00
Yidong Li
e2f8d9e309
Merge pull request #737 from MaffooBristol/patch-1
Rename component in README example code
2019-06-26 17:13:19 +08:00
Yidong Li
4a13acfb03
Merge branch 'master' into patch-1 2019-06-26 17:12:26 +08:00
Yidong Li
5e4c9852a5
Merge pull request #916 from nialexsan/patch-1
fixed flow typing
2019-06-26 16:51:27 +08:00
Yidong Li
ee6c352444
Merge pull request #831 from alattanzio/master
added scrollTo
2019-06-26 16:31:27 +08:00
Yidong Li
cff749e7c6
Remove Arial font style 2019-06-26 16:30:04 +08:00
Yidong Li
5a6a9f59ce
Merge pull request #931 from danielholmes/patch-1
Add missing scrollBy TypeScript definition
2019-06-26 16:16:38 +08:00
Yidong Li
4d4b26e06a
Merge branch 'master' into patch-1 2019-06-26 16:14:02 +08:00
Yidong Li
6503b1cfb6
Merge pull request #1000 from leecade/develop
fix(types): correct the wrong types
2019-06-26 14:01:52 +08:00
李宜东
3fc6449780 fix(types): correct the wrong types
re #912
2019-06-26 13:57:40 +08:00
Yidong Li
846e13f58c
Merge pull request #958 from chr22/patch-1
Update index.d.ts
2019-06-26 13:28:46 +08:00
Yidong Li
b71ac8dbb6
Merge branch 'master' into patch-1 2019-06-26 13:27:08 +08:00
斯人
288ce99397
docs(readme): remove ad 2019-06-26 12:25:58 +08:00
Yidong Li
7f51a00bba
Merge pull request #997 from leecade/develop
build(ViewPagerAndroid): from react-native => @react-native-community/viewpager
2019-06-26 12:15:17 +08:00
李宜东
bba003f23f docs(v1.6.0-dev): update changelog and installation guide 2019-06-26 11:55:56 +08:00
李宜东
a808eed809 build(ViewPagerAndroid): from react-native => @react-native-community/viewpager 2019-06-26 11:55:29 +08:00
Yidong Li
515257506b
Merge pull request #995 from leecade/develop
feat(types): add missed containerStyle prop
2019-06-24 01:05:08 +08:00
ArrayZoneYour
27b51f9de9 feat(types): add missed containerStyle prop
fix #974, fix #878, close #900
2019-06-24 00:52:32 +08:00
ArrayZoneYour
28294b7dfc style(prettier): add .prettierrc file 2019-06-24 00:27:51 +08:00
ArrayZoneYour
f6f656b3a0 build(yarn): remove the lock file 2019-06-23 23:39:26 +08:00
Christian Svejstrup
f81e260915
Update index.d.ts
loadMinimalSize should be a number not a boolean, so that you can set the amount of pages to render.
2019-03-22 17:21:04 +01:00
deepakaggarwal7
facd667a58
Update index.js
Solves the issue of state messing up when parent component calls setState [ref https://github.com/leecade/react-native-swiper/issues/569]
2019-02-23 19:18:10 +05:30
Daniel Holmes
4e8fbc54b6
Add missing scrollBy TypeScript definition
As outlined [in the README](https://github.com/leecade/react-native-swiper#methods)
2019-02-07 08:00:27 +11:00
Alex
70d1218b11
fixed flow typing 2019-01-03 10:22:39 -05:00
Bart Arribe
e4dbde6657
Merge pull request #897 from leecade/release1.5.14
Release 1.5.14
2018-11-26 11:30:44 +01:00
Bart Arribe
cb8c080a8f Release 1.5.14 2018-11-26 11:07:33 +01:00
Bart Arribe
6333668c36
Merge pull request #789 from fungilation/master
fixes #582 (Android not setting this onLayout first?)
2018-11-26 11:02:18 +01:00
Gary Fung
658923f707 resolve styling conflict 2018-11-23 08:56:38 +07:00
Gary Fung
23d62e09e4 fixed styling (indent) 2018-11-21 22:40:43 +08:00
Bart Arribe
1ca92e5afe
Merge pull request #684 from tezqa/master
Add onScrollBegin and onTouchEnd for Android
2018-11-21 10:52:44 +01:00
斯人
d786dffc88
Merge pull request #838 from thealiilman/patch-1
Updated README.md
2018-09-20 18:14:32 +08:00
斯人
e6bcc4e2e4
Merge pull request #866 from retyui/flowtyped
Add flow definitions
2018-09-20 18:14:09 +08:00
David Narbutovich
7afcdd7c9d Add flow definitions 2018-09-20 13:05:21 +03:00
斯人
008ed8bb8a
Update recruit 2018-09-11 21:10:43 +08:00
斯人
81dd7be33e
Update recruit ad 2018-09-11 21:05:41 +08:00
Gary Fung
2c52e01067 https://github.com/leecade/react-native-swiper/pull/684 to fix onScrollBeginDrag not being called on Android 2018-08-28 13:23:46 -07:00
Ali Ilman
30cc488c46
Updated README.md
Added containerStyle prop in Properties section
2018-07-25 13:11:47 +08:00
alattanzio
be1b3beb84
Merge pull request #2 from alattanzio/alattanzio-patch-2
Added scrollTo
2018-07-17 16:11:37 +12:00
alattanzio
64fdd5cfbd
Added scrollTo 2018-07-17 16:08:20 +12:00
Gary Fung
4fc5eab25e fixes #582 (Android not setting this onLayout first?) 2018-05-23 16:48:07 -07:00
Matt Fletcher
f3276c9659
Rename component in README example code
Both the imported variable and the exported component class are named "Swiper", which means that the example code fails as it stands. I propose changing the name from "Swiper" to "SwiperComponent" to allow this example code to be a MCVE.
2018-02-28 16:03:21 +00:00
Bart Arribe
a1e052e485
Merge pull request #695 from petermiles/master
Update README to full ES6 goodiness
2018-02-05 22:50:49 +01:00
Bart Arribe
cf9cc5a83c
Merge pull request #697 from andrew/patch-1
Update license field in package.json to match LICENSE file
2018-02-05 22:50:02 +01:00
Bart Arribe
06e0fa5a07
Merge pull request #719 from lamson/patch-1
Correcting type `autoplayTimeout: number` prop
2018-02-05 22:42:51 +01:00
Bart Arribe
57f87ce4ef
Merge pull request #690 from TheMarsGuy/master
Remove fontFamily: 'Arial'.
2018-02-05 22:42:05 +01:00
Son Nguyen
456157f71c
Correcting type autoplayTimeout: number prop
Likely a copy/paste error. The timeout should be type `number` instead of `boolean`
2018-01-29 22:14:39 -08:00
guodf
2e3c812965
fix #623
Resolve ES6 and CommonJS compatibility issues
2018-01-25 23:56:27 +08:00
Andrew Nesbitt
76ac03cde5
Update license field in package.json to match LICENSE file
MIT instead of ISC
2017-12-19 13:18:33 +00:00
Peter Miles
00f429d6b2
Update README.md 2017-12-17 20:59:38 -06:00
Peter Miles
7bf6a49860
Update README.md 2017-12-17 20:57:50 -06:00
MarsGuy
d6c696d3b2
Remove fontFamily: 'Arial'.
* Solves https://github.com/leecade/react-native-swiper/issues/444
2017-12-11 13:56:10 +05:30
Samir Moussouni
4f6554f440 Add onScrollBegin and onTouchEnd for Android 2017-12-06 10:50:19 +01:00
Bart Arribe
5336a4ac2c Merge pull request #597 from leecade/bumpVersion
Bump version
2017-10-02 20:17:38 +02:00
12 changed files with 1966 additions and 1084 deletions

3
.gitignore vendored
View File

@ -39,3 +39,6 @@ examples/swiper.xcodeproj/xcuserdata
# Vim
*.sw*
dist/
# yarn
yarn.lock

10
.prettierrc Normal file
View File

@ -0,0 +1,10 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": true,
"jsxBracketSameLine": false
}

View File

@ -1,103 +1,129 @@
- [1.6.0-dev]
- ViewPagerAndroid: react-native => @react-native-community/viewpager
- add TypeScript typing of containerStyle
- [1.5.14]
- fixes #582 (Android not setting this onLayout first?) #789 (thanks [@fungilation](https://github.com/fungilation))
- Add onScrollBegin and onTouchEnd for Android #684 (thanks [@kostyaVyrodov](https://github.com/kostyaVyrodov))
- [1.5.13]
+ Workaround for react-native 0.4.8 contentOffset regression #572 (thanks @nixoz)
+ Fix wrong calculation of width and height after device rotation #581 (thanks @kostyaVyrodov)
+ Calculated width & height on layout, used later on re-rendering. Possibility to change ScrollView styles #548 (thanks @germanst)
- Workaround for react-native 0.4.8 contentOffset regression #572 (thanks [@nixoz](https://github.com/nixoz))
- Fix wrong calculation of width and height after device rotation #581 (thanks [@kostyaVyrodov](https://github.com/kostyaVyrodov))
- Calculated width & height on layout, used later on re-rendering. Possibility to change ScrollView styles #548 (thanks [@germanst](https://github.com/germanst))
- [1.5.12]
+ Update core packages
+ Optionally disable the 'next' control button (thanks [@SSTPIERRE2](https://github.com/SSTPIERRE2))
+ Fix `Uncaught TypeError: _this.refs.scrollView.scrollTo is not a function` (thanks [@flyskywhy](https://github.com/flyskywhy))
+ Allow dotStyle and activeDotStyle PropTypes to accept Stylesheet (thanks [@knopt](https://github.com/knopt))
+ Calculate the offset in the initial state instead of `onLayout` (thanks [@kjkta](https://github.com/kjkta))
- Update core packages
- Optionally disable the 'next' control button (thanks [@SSTPIERRE2](https://github.com/SSTPIERRE2))
- Fix `Uncaught TypeError: _this.refs.scrollView.scrollTo is not a function` (thanks [@flyskywhy](https://github.com/flyskywhy))
- Allow dotStyle and activeDotStyle PropTypes to accept Stylesheet (thanks [@knopt](https://github.com/knopt))
- Calculate the offset in the initial state instead of `onLayout` (thanks [@kjkta](https://github.com/kjkta))
- [1.5.11]
+ Typescript Definition
- Typescript Definition
- [1.5.1]
+ Allow scroll without animate, ref: [scrollBy(index, animated)](#scrollbyindex-animated)
+ Remove [#254](https://github.com/leecade/react-native-swiper/pull/254) which break the scroll direction in loop mode
- Allow scroll without animate, ref: [scrollBy(index, animated)](#scrollbyindex-animated)
- Remove [#254](https://github.com/leecade/react-native-swiper/pull/254) which break the scroll direction in loop mode
- [1.5.0]
+ Improve develop [workflow](#development) for support watch & use real pkg name in examples
+ Update examples for support `React-native 0.33` + `Xcode8` + `ios10` + `iphone7`
+ Switch to [standard](https://github.com/feross/standard) code style
+ Rewrite source code with ES6 syntex
+ Cancel transform the source code when publish
+ Add a [demo](examples/components/LoadMinimal) for `loadMinimal` + `lazyload`
+ Add a [demo](examples/components/PhotoView) for multi-images viewer
+ [#254](https://github.com/leecade/react-native-swiper/pull/254) Fix jitter when quickly swiping back and forth between pages (iOS) (@thanks [@nemophrost](https://github.com/nemophrost)).
- Improve develop [workflow](#development) for support watch & use real pkg name in examples
- Update examples for support `React-native 0.33` + `Xcode8` + `ios10` + `iphone7`
- Switch to [standard](https://github.com/feross/standard) code style
- Rewrite source code with ES6 syntex
- Cancel transform the source code when publish
- Add a [demo](examples/components/LoadMinimal) for `loadMinimal` + `lazyload`
- Add a [demo](examples/components/PhotoView) for multi-images viewer
- [#254](https://github.com/leecade/react-native-swiper/pull/254) Fix jitter when quickly swiping back and forth between pages (iOS) (@thanks [@nemophrost](https://github.com/nemophrost)).
- [1.4.11]
+ Adds loadMinimalSize property
- Adds loadMinimalSize property
- [1.4.10]
+ Adds loadMinimal to api (lazyloading-esque)
- Adds loadMinimal to api (lazyloading-esque)
- [1.4.9]
+ Adds extra check for title
- Adds extra check for title
- [1.4.8]
+ Fixes loop and autoplay bugs in android
- Fixes loop and autoplay bugs in android
- [1.4.7]
+ Don't attempt to mutate this.props
+ Fixes examples links
+ Adds drag end handling to always reset state.isScrolling
+ Fixes float calculation error
- Don't attempt to mutate this.props
- Fixes examples links
- Adds drag end handling to always reset state.isScrolling
- Fixes float calculation error
- [1.4.6]
+ refactors examples
+ prevents mutation of `this.props`
+ fixes android index loop issue
- refactors examples
- prevents mutation of `this.props`
- fixes android index loop issue
- [1.4.5]
+ renames `scrollTo()` to `scrollBy()`
+ image index is now always an integer
+ prevents parent state updates from reseting index counter
+ fixes issue with scrolling not working sometimes
- renames `scrollTo()` to `scrollBy()`
- image index is now always an integer
- prevents parent state updates from reseting index counter
- fixes issue with scrolling not working sometimes
- [1.4.4]
+ Support for React Native latest(`^0.26.0`)
+ Updates examples to work with react-native-swiper 1.4.4
+ Examples now run on Android (some are still buggy, needs more work)
+ Removes old examples folder
- Support for React Native latest(`^0.26.0`)
- Updates examples to work with react-native-swiper 1.4.4
- Examples now run on Android (some are still buggy, needs more work)
- Removes old examples folder
- [1.4.3]
+ Fixed auto play issue when only a child view
- Fixed auto play issue when only a child view
- [v1.4.0]
+ Support for React Native latest(`^0.17.0`) & Upgrade examples base on Xcode `7.2` / React Native `0.17.0`
+ Upgrade build tool to babel6
- Support for React Native latest(`^0.17.0`) & Upgrade examples base on Xcode `7.2` / React Native `0.17.0`
+ Add missing deps `react-timer-mixin`
- Upgrade build tool to babel6
+ [1f8643a](https://github.com/leecade/react-native-swiper/commit/1f8643a67e2768d165132a19629a991a86672036) Move Dimensions import to deconstructed React import for react-native (@thanks [@jedrekk](https://github.com/jedrekk)).
- Add missing deps `react-timer-mixin`
+ [e28af9b](https://github.com/leecade/react-native-swiper/commit/e28af9b205f17447cb3149b45fc220beec037bce) Support index property in combination with loop property (@thanks [@almost](https://github.com/almost)).
- [1f8643a](https://github.com/leecade/react-native-swiper/commit/1f8643a67e2768d165132a19629a991a86672036) Move Dimensions import to deconstructed React import for react-native (@thanks [@jedrekk](https://github.com/jedrekk)).
+ [6c832d](https://github.com/leecade/react-native-swiper/commit/6c832d6a23da3737a2e8a2667273dc6093bcc9ee) fix warnings about keys for dots (@thanks [@sunnylqm](https://github.com/sunnylqm)).
- [e28af9b](https://github.com/leecade/react-native-swiper/commit/e28af9b205f17447cb3149b45fc220beec037bce) Support index property in combination with loop property (@thanks [@almost](https://github.com/almost)).
+ [8de1afc](https://github.com/leecade/react-native-swiper/commit/8de1afcb75a003424231bb089802db53bbbf84e4) Changes to make the example work in xcode 7 (@thanks [@allomov](https://github.com/allomov)).
- [6c832d](https://github.com/leecade/react-native-swiper/commit/6c832d6a23da3737a2e8a2667273dc6093bcc9ee) fix warnings about keys for dots (@thanks [@sunnylqm](https://github.com/sunnylqm)).
- [8de1afc](https://github.com/leecade/react-native-swiper/commit/8de1afcb75a003424231bb089802db53bbbf84e4) Changes to make the example work in xcode 7 (@thanks [@allomov](https://github.com/allomov)).
- [v1.3.0]
+ [8d6d75c](https://github.com/leecade/react-native-swiper/commit/8d6d75c00edf87b603c218aad0018932277814b5) inject `state` in ScrollResponders (@thanks [@smothers](https://github.com/smothers)).
- [8d6d75c](https://github.com/leecade/react-native-swiper/commit/8d6d75c00edf87b603c218aad0018932277814b5) inject `state` in ScrollResponders (@thanks [@smothers](https://github.com/smothers)).
- [v1.2.2]
+ [890c0ce](https://github.com/leecade/react-native-swiper/commit/890c0ce64e2192c2ca7830e6699f67b88171e74b) ensure `onMomentumScrollEnd` synchronous update `index`.
- [890c0ce](https://github.com/leecade/react-native-swiper/commit/890c0ce64e2192c2ca7830e6699f67b88171e74b) ensure `onMomentumScrollEnd` synchronous update `index`.
- [v1.2.0]
+ [838b24c](https://github.com/leecade/react-native-swiper/commit/838b24cbeaf49b9ca1dabb4eed8305e314503fb1) Re-design a loop model for avoid img flickering.
+ [9cb91c5](https://github.com/leecade/react-native-swiper/commit/9cb91c58c84034b0b8b874dbfc2a44da982686a8) fixes [#7](https://github.com/leecade/react-native-swiper/issues/6) `onMomentumScrollEnd` lost `event` param. (thanks [@smothers](https://github.com/smothers))
- [838b24c](https://github.com/leecade/react-native-swiper/commit/838b24cbeaf49b9ca1dabb4eed8305e314503fb1) Re-design a loop model for avoid img flickering.
- [9cb91c5](https://github.com/leecade/react-native-swiper/commit/9cb91c58c84034b0b8b874dbfc2a44da982686a8) fixes [#7](https://github.com/leecade/react-native-swiper/issues/6) `onMomentumScrollEnd` lost `event` param. (thanks [@smothers](https://github.com/smothers))
- [v1.1.1]
+ [21f0b00](https://github.com/leecade/react-native-swiper/commit/21f0b00138b6936cd3dfac2eb107a14c99c7392b) fixes [#6](https://github.com/leecade/react-native-swiper/issues/6) a define-propType error. (thanks [@benjamingeorge](https://github.com/benjamingeorge))
- [21f0b00](https://github.com/leecade/react-native-swiper/commit/21f0b00138b6936cd3dfac2eb107a14c99c7392b) fixes [#6](https://github.com/leecade/react-native-swiper/issues/6) a define-propType error. (thanks [@benjamingeorge](https://github.com/benjamingeorge))
- [v1.1.0]
+ [44ec630](https://github.com/leecade/react-native-swiper/commit/44ec630b62844dbeaccee73adaa0996e319ebffb) fixes [#4](https://github.com/leecade/react-native-swiper/issues/4) `onMoementumScrollEnd` gets overridden. (thanks [@subpublicanders](https://github.com/subpublicanders))
+ [5de06a7](https://github.com/leecade/react-native-swiper/commit/5de06a7aa86318ad38720728022b80e5cf98a2ab) New prop: `renderPagination`. (thanks [@aksonov](https://github.com/aksonov))
- [44ec630](https://github.com/leecade/react-native-swiper/commit/44ec630b62844dbeaccee73adaa0996e319ebffb) fixes [#4](https://github.com/leecade/react-native-swiper/issues/4) `onMoementumScrollEnd` gets overridden. (thanks [@subpublicanders](https://github.com/subpublicanders))
- [5de06a7](https://github.com/leecade/react-native-swiper/commit/5de06a7aa86318ad38720728022b80e5cf98a2ab) New prop: `renderPagination`. (thanks [@aksonov](https://github.com/aksonov))
- [v1.0.4]
+ [21cb373](https://github.com/leecade/react-native-swiper/commit/21cb3732578588f9d47ee7ddda541577ad691970) fixes [#2](https://github.com/leecade/react-native-swiper/issues/2) Solve the problem of installation. (thanks [@jamwaffles](https://github.com/jamwaffles))
- [21cb373](https://github.com/leecade/react-native-swiper/commit/21cb3732578588f9d47ee7ddda541577ad691970) fixes [#2](https://github.com/leecade/react-native-swiper/issues/2) Solve the problem of installation. (thanks [@jamwaffles](https://github.com/jamwaffles))
- [v1.0.3]
+ [0f796f3](https://github.com/leecade/react-native-swiper/commit/0f796f3557b5aeb1772573cd7ecae2e835bccc0b) fixes [#1](https://github.com/leecade/react-native-swiper/issues/1) Two 'horizontal' in propTypes. (thanks [@MacyzZ](https://github.com/MacyzZ))
- [0f796f3](https://github.com/leecade/react-native-swiper/commit/0f796f3557b5aeb1772573cd7ecae2e835bccc0b) fixes [#1](https://github.com/leecade/react-native-swiper/issues/1) Two 'horizontal' in propTypes. (thanks [@MacyzZ](https://github.com/MacyzZ))

232
README.md
View File

@ -22,27 +22,45 @@
> see: [ROADMAP.md](ROADMAP.md)
## Changelogs
- **[1.5.6]**
+ Fix [#16](https://github.com/leecade/react-native-swiper/issues/16), [#36](https://github.com/leecade/react-native-swiper/issues/36), [#371](https://github.com/leecade/react-native-swiper/issues/371), [#410](https://github.com/leecade/react-native-swiper/issues/410), [#411](https://github.com/leecade/react-native-swiper/issues/411), [#422](https://github.com/leecade/react-native-swiper/issues/422), [#468](https://github.com/leecade/react-native-swiper/issues/468) Fix landscape orientation auto resize! (thanks [@ahmed3mar](https://github.com/ahmed3mar), [@timmywil](https://github.com/timmywil))
+ Add containerStyle prop to customize the view container.
- [1.5.5]
+ Update: using PropTypes from prop-types and Change View.propTypes to ViewPropTypes
- **[1.6.0-nightly]**
- Dependency
- Remove ViewPagerAndroid, use ScrollView #1009
- TypeScript
- correct the wrong types #1000
- Add missing scrollBy TypeScript definition #931
- New Feature
- add scrollTo #831
- Added prop to disable the PrevButton #749
- Optionally render page #1004
- Bug Fix
- ES6 and CommonJS compatibility #717
- Solves the issue of state messing up when parent component calls setState #939
- replay when autoplay is setted to true #1002
* [1.5.6]
- Fix [#16](https://github.com/leecade/react-native-swiper/issues/16), [#36](https://github.com/leecade/react-native-swiper/issues/36), [#371](https://github.com/leecade/react-native-swiper/issues/371), [#410](https://github.com/leecade/react-native-swiper/issues/410), [#411](https://github.com/leecade/react-native-swiper/issues/411), [#422](https://github.com/leecade/react-native-swiper/issues/422), [#468](https://github.com/leecade/react-native-swiper/issues/468) Fix landscape orientation auto resize! (thanks [@ahmed3mar](https://github.com/ahmed3mar), [@timmywil](https://github.com/timmywil))
- Add containerStyle prop to customize the view container.
* [1.5.5]
- Update: using PropTypes from prop-types and Change View.propTypes to ViewPropTypes
- [1.5.4]
+ Added easily accessible pagination point manipulation: use `dotColor` / `activeDotColor` and `dotStyle` / `activeDotStyle` (thanks [@denizs](https://github.com/denizs))
+ Added scrollEnabled prop to documentation (thanks [@ibandominguez](https://github.com/ibandominguez))
- Added easily accessible pagination point manipulation: use `dotColor` / `activeDotColor` and `dotStyle` / `activeDotStyle` (thanks [@denizs](https://github.com/denizs))
- Added scrollEnabled prop to documentation (thanks [@ibandominguez](https://github.com/ibandominguez))
- [1.5.3]
+ Add loadMinimalLoader prop to customize `<ActivityIndicator />` (thanks [@Exilz](https://github.com/Exilz))
+ Disable autoplay timer when prop changes to false (thanks [@dizlexik](https://github.com/dizlexik))
+ Special thanks to [@hypatiah](https://github.com/dizlexik) for fixed some grammatical errors in README
- Add loadMinimalLoader prop to customize `<ActivityIndicator />` (thanks [@Exilz](https://github.com/Exilz))
- Disable autoplay timer when prop changes to false (thanks [@dizlexik](https://github.com/dizlexik))
- Special thanks to [@hypatiah](https://github.com/dizlexik) for fixed some grammatical errors in README
- [1.5.2]
+ Add yarn lock
+ Fix jitter when quickly swiping back and forth between pages (iOS) (thanks [@nemophrost](https://github.com/nemophrost))
+ The first webview always reloaded when injecting the rest of the children (thanks [@eosterberg](https://github.com/eosterberg))
- Add yarn lock
- Fix jitter when quickly swiping back and forth between pages (iOS) (thanks [@nemophrost](https://github.com/nemophrost))
- The first webview always reloaded when injecting the rest of the children (thanks [@eosterberg](https://github.com/eosterberg))
> see more: [CHANGELOG.md](CHANGELOG.md)
@ -70,29 +88,36 @@
![](http://i.imgur.com/LAOHbJA.gif=300x)
## Getting Started
- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Properties](#properties)
+ [Basic](#basic)
+ [Custom basic style & content](#custom-basic-style--content)
+ [Pagination](#pagination)
+ [Autoplay](#autoplay)
+ [Control buttons](#control-buttons)
+ [Props of Children](#props-of-children)
+ [Basic props of `<ScrollView />`](#basic-props-of-scrollview-)
+ [Supported ScrollResponder](#supported-scrollresponder)
- [Basic](#basic)
- [Custom basic style & content](#custom-basic-style--content)
- [Pagination](#pagination)
- [Autoplay](#autoplay)
- [Control buttons](#control-buttons)
- [Props of Children](#props-of-children)
- [Basic props of `<ScrollView />`](#basic-props-of-scrollview-)
- [Supported ScrollResponder](#supported-scrollresponder)
- [Examples](#examples)
- [Development](#development)
### Installation
> v1.5.14
```bash
$ npm i react-native-swiper --save
```
> v1.6.0-nightly
```
npm i --save react-native-swiper@nightly
```
### Basic Usage
- Install `react-native` first
@ -110,46 +135,40 @@ $ react-native init myproject
- Then, edit `myproject/index.ios.js`, like this:
```jsx
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
import React, { Component } from 'react'
import { AppRegistry, StyleSheet, Text, View } from 'react-native'
import Swiper from 'react-native-swiper';
import Swiper from 'react-native-swiper'
var styles = StyleSheet.create({
wrapper: {
},
const styles = StyleSheet.create({
wrapper: {},
slide1: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#9DD6EB',
backgroundColor: '#9DD6EB'
},
slide2: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#97CAE5',
backgroundColor: '#97CAE5'
},
slide3: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#92BBD9',
backgroundColor: '#92BBD9'
},
text: {
color: '#fff',
fontSize: 30,
fontWeight: 'bold',
fontWeight: 'bold'
}
})
var swiper = React.createClass({
render: function() {
export default class SwiperComponent extends Component {
render() {
return (
<Swiper style={styles.wrapper} showsButtons={true}>
<View style={styles.slide1}>
@ -164,99 +183,100 @@ var swiper = React.createClass({
</Swiper>
)
}
})
}
AppRegistry.registerComponent('myproject', () => swiper);
AppRegistry.registerComponent('myproject', () => SwiperComponent)
```
### Properties
#### Basic
| Prop | Default | Type | Description |
| :------------ |:---------------:| :---------------:| :-----|
| horizontal | true | `bool` | If `true`, the scroll view's children are arranged horizontally in a row instead of vertically in a column. |
| loop | true | `bool` | Set to `false` to disable continuous loop mode. |
| index | 0 | `number` | Index number of initial slide. |
| showsButtons | false | `bool` | Set to `true` make control buttons visible. |
| autoplay | false | `bool` | Set to `true` enable auto play mode. |
| onIndexChanged | (index) => null | `func` | Called with the new index when the user swiped |
| Prop | Default | Type | Description |
| :------------- | :-------------: | :------: | :---------------------------------------------------------------------------------------------------------- |
| horizontal | true | `bool` | If `true`, the scroll view's children are arranged horizontally in a row instead of vertically in a column. |
| loop | true | `bool` | Set to `false` to disable continuous loop mode. |
| index | 0 | `number` | Index number of initial slide. |
| showsButtons | false | `bool` | Set to `true` make control buttons visible. |
| autoplay | false | `bool` | Set to `true` enable auto play mode. |
| onIndexChanged | (index) => null | `func` | Called with the new index when the user swiped |
#### Custom basic style & content
| Prop | Default | Type | Description |
| :------------ |:---------------:| :---------------:| :-----|
| width | - | `number` | If no specify default enable fullscreen mode by `flex: 1`. |
| height | - | `number` | If no specify default fullscreen mode by `flex: 1`. |
| style | {...} | `style` | See default style in source. |
| loadMinimal | false | `bool` | Only load current index slide , `loadMinimalSize` slides before and after. |
| loadMinimalSize | 1 | `number` | see `loadMinimal` |
| loadMinimalLoader | `<ActivityIndicator />` | `element` | Custom loader to display when slides aren't loaded
| Prop | Default | Type | Description |
| :---------------- | :---------------------: | :-------: | :------------------------------------------------------------------------- |
| width | - | `number` | If no specify default enable fullscreen mode by `flex: 1`. |
| height | - | `number` | If no specify default fullscreen mode by `flex: 1`. |
| style | {...} | `style` | See default style in source. |
| containerStyle | {...} | `style` | See default container style in source. |
| loadMinimal | false | `bool` | Only load current index slide , `loadMinimalSize` slides before and after. |
| loadMinimalSize | 1 | `number` | see `loadMinimal` |
| loadMinimalLoader | `<ActivityIndicator />` | `element` | Custom loader to display when slides aren't loaded |
#### Pagination
| Prop | Default | Type | Description |
| :------------ |:---------------:| :---------------:| :-----|
| showsPagination | true | `bool` | Set to `true` make pagination visible. |
| paginationStyle | {...} | `style` | Custom styles will merge with the default styles. |
| renderPagination | - | `function` | Complete control how to render pagination with three params (`index`, `total`, `context`) ref to `this.state.index` / `this.state.total` / `this`, For example: show numbers instead of dots. |
| dot | `<View style={{backgroundColor:'rgba(0,0,0,.2)', width: 8, height: 8,borderRadius: 4, marginLeft: 3, marginRight: 3, marginTop: 3, marginBottom: 3,}} />` | `element` | Allow custom the dot element. |
| activeDot | `<View style={{backgroundColor: '#007aff', width: 8, height: 8, borderRadius: 4, marginLeft: 3, marginRight: 3, marginTop: 3, marginBottom: 3,}} />` | `element` | Allow custom the active-dot element. |
| dotStyle | - | `object` | Allow custom the active-dot element. |
| dotColor | - | `string` | Allow custom the active-dot element. |
| activeDotColor | - | `string` | Allow custom the active-dot element. |
| activeDotStyle | - | `object` | Allow custom the active-dot element. |
| Prop | Default | Type | Description |
| :--------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------: | :--------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| showsPagination | true | `bool` | Set to `true` make pagination visible. |
| paginationStyle | {...} | `style` | Custom styles will merge with the default styles. |
| renderPagination | - | `function` | Complete control how to render pagination with three params (`index`, `total`, `context`) ref to `this.state.index` / `this.state.total` / `this`, For example: show numbers instead of dots. |
| dot | `<View style={{backgroundColor:'rgba(0,0,0,.2)', width: 8, height: 8,borderRadius: 4, marginLeft: 3, marginRight: 3, marginTop: 3, marginBottom: 3,}} />` | `element` | Allow custom the dot element. |
| activeDot | `<View style={{backgroundColor: '#007aff', width: 8, height: 8, borderRadius: 4, marginLeft: 3, marginRight: 3, marginTop: 3, marginBottom: 3,}} />` | `element` | Allow custom the active-dot element. |
| dotStyle | - | `object` | Allow custom the active-dot element. |
| dotColor | - | `string` | Allow custom the active-dot element. |
| activeDotColor | - | `string` | Allow custom the active-dot element. |
| activeDotStyle | - | `object` | Allow custom the active-dot element. |
#### Autoplay
| Prop | Default | Type | Description |
| :------------ |:---------------:| :---------------:| :-----|
| autoplay | true | `bool` | Set to `true` enable auto play mode. |
| autoplayTimeout | 2.5 | `number` | Delay between auto play transitions (in second). |
| autoplayDirection | true | `bool` | Cycle direction control. |
| Prop | Default | Type | Description |
| :---------------- | :-----: | :------: | :----------------------------------------------- |
| autoplay | true | `bool` | Set to `true` enable auto play mode. |
| autoplayTimeout | 2.5 | `number` | Delay between auto play transitions (in second). |
| autoplayDirection | true | `bool` | Cycle direction control. |
#### Control buttons
| Prop | Default | Type | Description |
| :------------ |:---------------:| :---------------:| :-----|
| showsButtons | true | `bool` | Set to `true` make control buttons visible. |
| buttonWrapperStyle | `{backgroundColor: 'transparent', flexDirection: 'row', position: 'absolute', top: 0, left: 0, flex: 1, paddingHorizontal: 10, paddingVertical: 10, justifyContent: 'space-between', alignItems: 'center'}` | `style` | Custom styles. |
| nextButton | `<Text style={styles.buttonText}></Text>` | `element` | Allow custom the next button. |
| prevButton | `<Text style={styles.buttonText}></Text>` | `element` | Allow custom the prev button. |
| Prop | Default | Type | Description |
| :----------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------: | :------------------------------------------ |
| showsButtons | true | `bool` | Set to `true` make control buttons visible. |
| buttonWrapperStyle | `{backgroundColor: 'transparent', flexDirection: 'row', position: 'absolute', top: 0, left: 0, flex: 1, paddingHorizontal: 10, paddingVertical: 10, justifyContent: 'space-between', alignItems: 'center'}` | `style` | Custom styles. |
| nextButton | `<Text style={styles.buttonText}></Text>` | `element` | Allow custom the next button. |
| prevButton | `<Text style={styles.buttonText}></Text>` | `element` | Allow custom the prev button. |
#### Props of Children
| Prop | Default | Type | Description |
| :------------ |:---------------:| :---------------:| :-----|
| style | {...} | `style` | Custom styles will merge with the default styles. |
| Prop | Default | Type | Description |
| :---- | :----------------------------------: | :-------: | :------------------------------------------------------------- |
| style | {...} | `style` | Custom styles will merge with the default styles. |
| title | {<Text numberOfLines={1}>...</Text>} | `element` | If this parameter is not specified, will not render the title. |
#### Basic props of `<ScrollView />`
| Prop | Default | Type | Description |
| :------------ |:---------------:| :---------------:| :-----|
| horizontal | true | `bool` | If `true`, the scroll view's children are arranged horizontally in a row instead of vertically in a column. |
| pagingEnabled | true | `bool` | If true, the scroll view stops on multiples of the scroll view's size when scrolling. This can be used for horizontal pagination. |
| showsHorizontalScrollIndicator | false | `bool` | Set to `true` if you want to show horizontal scroll bar. |
| showsVerticalScrollIndicator | false | `bool` | Set to `true` if you want to show vertical scroll bar. |
| bounces | false | `bool` | If `true`, the scroll view bounces when it reaches the end of the content if the content is larger then the scroll view along the axis of the scroll direction. If `false`, it disables all bouncing even if the alwaysBounce* props are true. |
| scrollsToTop | false | `bool` | If true, the scroll view scrolls to top when the status bar is tapped. |
| removeClippedSubviews | true | `bool` | If true, offscreen child views (whose overflow value is hidden) are removed from their native backing superview when offscreen. This canimprove scrolling performance on long lists. |
| automaticallyAdjustContentInsets | false | `bool` | Set to `true` if you need adjust content insets automation. |
| scrollEnabled | true | `bool` | Enables/Disables swiping |
| Prop | Default | Type | Description |
| :------------------------------- | :-----: | :----: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| horizontal | true | `bool` | If `true`, the scroll view's children are arranged horizontally in a row instead of vertically in a column. |
| pagingEnabled | true | `bool` | If true, the scroll view stops on multiples of the scroll view's size when scrolling. This can be used for horizontal pagination. |
| showsHorizontalScrollIndicator | false | `bool` | Set to `true` if you want to show horizontal scroll bar. |
| showsVerticalScrollIndicator | false | `bool` | Set to `true` if you want to show vertical scroll bar. |
| bounces | false | `bool` | If `true`, the scroll view bounces when it reaches the end of the content if the content is larger then the scroll view along the axis of the scroll direction. If `false`, it disables all bouncing even if the alwaysBounce\* props are true. |
| scrollsToTop | false | `bool` | If true, the scroll view scrolls to top when the status bar is tapped. |
| removeClippedSubviews | true | `bool` | If true, offscreen child views (whose overflow value is hidden) are removed from their native backing superview when offscreen. This canimprove scrolling performance on long lists. |
| automaticallyAdjustContentInsets | false | `bool` | Set to `true` if you need adjust content insets automation. |
| scrollEnabled | true | `bool` | Enables/Disables swiping |
> @see: http://facebook.github.io/react-native/docs/scrollview.html
#### Supported ScrollResponder
| Prop | Params | Type | Description |
| :------------ |:---------------:| :---------------:| :-----|
| onScrollBeginDrag | `e` / `state` / `context` | `function` | When animation begins after letting up |
| onMomentumScrollEnd | `e` / `state` / `context` | `function` | Makes no sense why this occurs first during bounce |
| onTouchStartCapture | `e` / `state` / `context` | `function` | Immediately after `onMomentumScrollEnd` |
| onTouchStart | `e` / `state` / `context` | `function` | Same, but bubble phase |
| onTouchEnd | `e` / `state` / `context` | `function` | You could hold the touch start for a long time |
| onResponderRelease | `e` / `state` / `context` | `function` | When lifting up - you could pause forever before * lifting |
| Prop | Params | Type | Description |
| :------------------ | :-----------------------: | :--------: | :---------------------------------------------------------- |
| onScrollBeginDrag | `e` / `state` / `context` | `function` | When animation begins after letting up |
| onMomentumScrollEnd | `e` / `state` / `context` | `function` | Makes no sense why this occurs first during bounce |
| onTouchStartCapture | `e` / `state` / `context` | `function` | Immediately after `onMomentumScrollEnd` |
| onTouchStart | `e` / `state` / `context` | `function` | Same, but bubble phase |
| onTouchEnd | `e` / `state` / `context` | `function` | You could hold the touch start for a long time |
| onResponderRelease | `e` / `state` / `context` | `function` | When lifting up - you could pause forever before \* lifting |
> Note: each ScrollResponder be injected with two params: `state` and `context`, you can get `state` and `context`(ref to swiper's `this`) from params, for example:
@ -286,10 +306,10 @@ Scroll by relative index.
Parameters:
| Name | Type | default | Description |
| :---- | :------: | :------: | :--- |
| index | `number` | `undefined` | offset index |
| animated | `bool` | `true` | offset index |
| Name | Type | default | Description |
| :------- | :------: | :---------: | :----------- |
| index | `number` | `undefined` | offset index |
| animated | `bool` | `true` | offset index |
### Examples

0
examples/android/gradlew vendored Executable file → Normal file
View File

View File

@ -2,6 +2,10 @@
# yarn lockfile v1
"@react-native-community/viewpager@^1.1.7":
version "1.1.7"
resolved "https://registry.yarnpkg.com/@react-native-community/viewpager/-/viewpager-1.1.7.tgz#7d3b1631f1ec91145db92a8e25c80d53027e96ba"
abab@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.3.tgz#b81de5f7274ec4e756d797cd834f303642724e5d"
@ -187,10 +191,6 @@ assert-plus@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-0.2.0.tgz#d74e1b87e7affc0db8aadb7021f3fe48101ab234"
async@^1.4.0:
version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
async@^2.1.4, async@^2.4.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/async/-/async-2.5.0.tgz#843190fd6b7357a0b9e1c956edddd5ec8462b54d"
@ -1074,6 +1074,10 @@ commander@^2.9.0:
version "2.11.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563"
commander@~2.20.0:
version "2.20.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"
compressible@~2.0.5:
version "2.0.11"
resolved "https://registry.yarnpkg.com/compressible/-/compressible-2.0.11.tgz#16718a75de283ed8e604041625a2064586797d8a"
@ -1332,8 +1336,8 @@ detect-indent@^4.0.0:
repeating "^2.0.0"
diff@^3.2.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.3.0.tgz#056695150d7aa93237ca7e378ac3b1682b7963b9"
version "3.5.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
dom-walk@^0.1.0:
version "0.1.1"
@ -1790,14 +1794,14 @@ gulplog@^1.0.0:
glogg "^1.0.0"
handlebars@^4.0.3:
version "4.0.10"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.0.10.tgz#3d30c718b09a3d96f23ea4cc1f403c4d3ba9ff4f"
version "4.1.2"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.1.2.tgz#b6b37c1ced0306b221e094fc7aca3ec23b131b67"
dependencies:
async "^1.4.0"
neo-async "^2.6.0"
optimist "^0.6.1"
source-map "^0.4.4"
source-map "^0.6.1"
optionalDependencies:
uglify-js "^2.6"
uglify-js "^3.1.4"
har-schema@^1.0.5:
version "1.0.5"
@ -2874,6 +2878,10 @@ negotiator@0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9"
neo-async@^2.6.0:
version "2.6.1"
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.1.tgz#ac27ada66167fa8849a6addd837f6b189ad2081c"
node-fetch@^1.0.1, node-fetch@^1.3.3:
version "1.7.1"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.1.tgz#899cb3d0a3c92f952c47f1b876f4c8aeabd400d5"
@ -3274,8 +3282,9 @@ react-devtools-core@^2.5.0:
ws "^2.0.3"
react-native-swiper@../:
version "1.5.12"
version "1.6.0-nightly.1"
dependencies:
"@react-native-community/viewpager" "^1.1.7"
prop-types "^15.5.10"
react-native@0.48.4:
@ -3763,16 +3772,14 @@ source-map-support@^0.4.2:
dependencies:
source-map "^0.5.6"
source-map@^0.4.4:
version "0.4.4"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.4.4.tgz#eba4f5da9c0dc999de68032d8b4f76173652036b"
dependencies:
amdefine ">=0.0.4"
source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.1:
version "0.5.6"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"
source-map@^0.6.1, source-map@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
source-map@~0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.2.0.tgz#dab73fbcfc2ba819b4de03bd6f6eaa48164b3f9d"
@ -3869,8 +3876,8 @@ string_decoder@~1.0.3:
safe-buffer "~5.1.0"
stringstream@~0.0.4:
version "0.0.5"
resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.5.tgz#4e484cd4de5a0bbbee18e46307710a8a81621878"
version "0.0.6"
resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.6.tgz#7880225b0d4ad10e30927d167a1d6f2fd3b33a72"
strip-ansi@^0.3.0:
version "0.3.0"
@ -4061,14 +4068,12 @@ uglify-js@2.7.5:
uglify-to-browserify "~1.0.0"
yargs "~3.10.0"
uglify-js@^2.6:
version "2.8.29"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.29.tgz#29c5733148057bb4e1f75df35b7a9cb72e6a59dd"
uglify-js@^3.1.4:
version "3.6.0"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.6.0.tgz#704681345c53a8b2079fb6cec294b05ead242ff5"
dependencies:
source-map "~0.5.1"
yargs "~3.10.0"
optionalDependencies:
uglify-to-browserify "~1.0.0"
commander "~2.20.0"
source-map "~0.6.1"
uglify-to-browserify@~1.0.0:
version "1.0.2"

243
index.d.ts vendored
View File

@ -1,106 +1,145 @@
import {
ViewStyle,
StyleProp,
NativeSyntheticEvent,
NativeScrollEvent
} from 'react-native'
import { Component } from 'react'
declare module 'react-native-swiper' {
import { ViewStyle } from 'react-native'
import { Component } from 'react'
interface SwiperProps {
// Basic
// If true, the scroll view's children are arranged horizontally in a row instead of vertically in a column.
horizontal?: boolean
// If no specify default enable fullscreen mode by flex: 1.
loop?: boolean
// Index number of initial slide.
index?: number
// Set to true make control buttons visible.
showsButtons?: boolean
// Set to false to disable continuous loop mode.
autoplay?: boolean
// Called with the new index when the user swiped
onIndexChanged?: any
// Custom basic style & content
// Set to true enable auto play mode.
width?: number
// If no specify default fullscreen mode by flex: 1.
height?: number
// See default style in source.
style?: ViewStyle
// Only load current index slide , loadMinimalSize slides before and after.
loadMinimal?: boolean
// see loadMinimal
loadMinimalSize?: boolean
// Custom loader to display when slides aren't loaded
loadMinimalLoader?: boolean
// Pagination
// Set to true make pagination visible.
showsPagination?: boolean
// Custom styles will merge with the default styles.
paginationStyle?: ViewStyle
// Complete control how to render pagination with three params (index, total, context) ref to this.state.index / this.state.total / this, For example: show numbers instead of dots.
renderPagination?: (index: number, total: number, swiper: Swiper) => JSX.Element
// Allow custom the dot element.
dot?: any
// Allow custom the active-dot element.
activeDot?: any
// Allow custom the active-dot element.
dotStyle?: ViewStyle
// Allow custom the active-dot element.
dotColor?: string
// Allow custom the active-dot element.
activeDotColor?: string
// Allow custom the active-dot element.
activeDotStyle?: ViewStyle
// Autoplay
// Delay between auto play transitions (in second).
autoplayTimeout?: boolean
// Cycle direction control.
autoplayDirection?: boolean
// Control buttons
// Set to true make control buttons visible.
buttonWrapperStyle?: any
// Allow custom the next button.
nextButton?: JSX.Element
// Allow custom the prev button.
prevButton?: JSX.Element
// Supported ScrollResponder
// When animation begins after letting up
onScrollBeginDrag?: any
// Makes no sense why this occurs first during bounce
onMomentumScrollEnd?: any
// Immediately after onMomentumScrollEnd
onTouchStartCapture?: any
// Same, but bubble phase
onTouchStart?: any
// You could hold the touch start for a long time
onTouchEnd?: any
// When lifting up - you could pause forever before * lifting
onResponderRelease?: any
// If true, the scroll view stops on multiples of the scroll view's size when scrolling. This can be used for
// horizontal pagination.
pagingEnabled?: boolean
// Set to true if you want to show horizontal scroll bar.
showsHorizontalScrollIndicator?: boolean
// Set to true if you want to show vertical scroll bar.
showsVerticalScrollIndicator?: boolean
// If true, the scroll view bounces when it reaches the end of the content if the content is larger then the
// scroll view along the axis of the scroll direction. If false, it disables all bouncing even if the
// alwaysBounce* props are true.
bounces?: boolean
// If true, the scroll view scrolls to top when the status bar is tapped.
scrollsToTop?: boolean
// If true, offscreen child views (whose overflow value is hidden) are removed from their native backing
// superview when offscreen. This canimprove scrolling performance on long lists.
removeClippedSubviews?: boolean
// Set to true if you need adjust content insets automation.
automaticallyAdjustContentInsets?: boolean
// Enables/Disables swiping
scrollEnabled?: boolean
interface SwiperStates {
autoplayEnd: false
loopJump: false
width: number
height: number
offset: {
x: number
y: number
}
total: number
index: number
dir: 'x' | 'y'
}
export default class Swiper extends Component<SwiperProps, any> {
}
interface SwiperInternals extends SwiperStates {
isScrolling: boolean
}
interface SwiperProps {
// Basic
// If true, the scroll view's children are arranged horizontally in a row instead of vertically in a column.
horizontal?: boolean
// If no specify default enable fullscreen mode by flex: 1.
loop?: boolean
// Index number of initial slide.
index?: number
// Set to true make control buttons visible.
showsButtons?: boolean
// Set to false to disable continuous loop mode.
autoplay?: boolean
// Called with the new index when the user swiped
onIndexChanged?: (index: number) => void
// Custom basic style & content
// Set to true enable auto play mode.
width?: number
// If no specify default fullscreen mode by flex: 1.
height?: number
// See default style in source.
style?: StyleProp<ViewStyle>
// Customize the View container.
containerStyle?: StyleProp<ViewStyle>
// Only load current index slide , loadMinimalSize slides before and after.
loadMinimal?: boolean
// see loadMinimal
loadMinimalSize?: number
// Custom loader to display when slides aren't loaded
loadMinimalLoader?: React.ReactNode
// Pagination
// Set to true make pagination visible.
showsPagination?: boolean
// Custom styles will merge with the default styles.
paginationStyle?: StyleProp<ViewStyle>
// Complete control how to render pagination with three params (index, total, context) ref to this.state.index / this.state.total / this, For example: show numbers instead of dots.
renderPagination?: (
index: number,
total: number,
swiper: Swiper
) => React.ReactNode
// Allow custom the dot element.
dot?: React.ReactNode
// Allow custom the active-dot element.
activeDot?: React.ReactNode
// Allow custom the active-dot element.
dotStyle?: StyleProp<ViewStyle>
// Allow custom the active-dot element.
dotColor?: string
// Allow custom the active-dot element.
activeDotColor?: string
// Allow custom the active-dot element.
activeDotStyle?: StyleProp<ViewStyle>
// Autoplay
// Delay between auto play transitions (in second).
autoplayTimeout?: number
// Cycle direction control.
autoplayDirection?: boolean
// Control buttons
// Set to true make control buttons visible.
buttonWrapperStyle?: StyleProp<ViewStyle>
// Allow custom the next button.
nextButton?: React.ReactNode
// Allow custom the prev button.
prevButton?: React.ReactNode
// Supported ScrollResponder
// When animation begins after letting up
onScrollBeginDrag?: (
e: NativeSyntheticEvent<NativeScrollEvent>,
state: SwiperInternals,
swiper: Swiper
) => void
// Makes no sense why this occurs first during bounce
onMomentumScrollEnd?: (
e: NativeSyntheticEvent<NativeScrollEvent>,
state: SwiperInternals,
swiper: Swiper
) => void
// Immediately after onMomentumScrollEnd
onTouchStartCapture?: any
// Same, but bubble phase
onTouchStart?: any
// You could hold the touch start for a long time
onTouchEnd?: any
// When lifting up - you could pause forever before * lifting
onResponderRelease?: any
// If true, the scroll view stops on multiples of the scroll view's size when scrolling. This can be used for
// horizontal pagination.
pagingEnabled?: boolean
// Set to true if you want to show horizontal scroll bar.
showsHorizontalScrollIndicator?: boolean
// Set to true if you want to show vertical scroll bar.
showsVerticalScrollIndicator?: boolean
// If true, the scroll view bounces when it reaches the end of the content if the content is larger then the
// scroll view along the axis of the scroll direction. If false, it disables all bouncing even if the
// alwaysBounce* props are true.
bounces?: boolean
// If true, the scroll view scrolls to top when the status bar is tapped.
scrollsToTop?: boolean
// If true, offscreen child views (whose overflow value is hidden) are removed from their native backing
// superview when offscreen. This canimprove scrolling performance on long lists.
removeClippedSubviews?: boolean
// Set to true if you need adjust content insets automation.
automaticallyAdjustContentInsets?: boolean
// Enables/Disables swiping
scrollEnabled?: boolean
}
export default class Swiper extends Component<SwiperProps> {
scrollBy: (index?: number, animated?: boolean) => void;
scrollTo: (index: number, animated?: boolean) => void;
}
}

View File

@ -1,2 +1,10 @@
import Swiper from './src/'
module.exports = Swiper
/**
* Resolve ES6 and CommonJS compatibility issues
* 1. CommonJS code
* const Swiper = require('react-native-swiper');
* 2. ES6 code
* import Swiper from 'react-native-swiper';
*/
module.exports = Swiper;
module.exports.default = Swiper;

111
index.js.flow Normal file
View File

@ -0,0 +1,111 @@
// @flow strict
// eslint-disable-next-line
import { Component, type Node } from 'react';
declare module 'react-native-swiper' {
// eslint-disable-next-line no-undef
declare export type SwiperProps = $ReadOnly<{|
// Basic
// If true, the scroll view's children are arranged horizontally in a row instead of vertically in a column.
horizontal?: ?boolean,
// If no specify default enable fullscreen mode by flex: 1.
loop?: ?boolean,
// Index number of initial slide.
index?: ?number,
// Set to true make control buttons visible.
showsButtons?: ?boolean,
// Set to false to disable continuous loop mode.
autoplay?: ?boolean,
// Called with the new index when the user swiped
onIndexChanged?: ?(index?: number) => void,
// Custom basic style & content
// Set to true enable auto play mode.
width?: ?number,
// If no specify default fullscreen mode by flex: 1.
height?: ?number,
// See default style in source.
style?: ?Object,
// Only load current index slide , loadMinimalSize slides before and after.
loadMinimal?: ?boolean,
// see loadMinimal
loadMinimalSize?: ?boolean,
// Custom loader to display when slides aren't loaded
loadMinimalLoader?: ?boolean,
// Pagination
// Set to true make pagination visible.
showsPagination?: ?boolean,
// Custom styles will merge with the default styles.
paginationStyle?: ?Object,
// Complete control how to render pagination with three params (index, total, context) ref to this.state.index / this.state.total / this, For example: show numbers instead of dots.
renderPagination?: ?(index: number, total: number, context: any) => Node,
// Allow custom the dot element.
dot?: ?Node,
// Allow custom the active-dot element.
activeDot?: ?Node,
// Allow custom the active-dot element.
dotStyle?: ?Object,
// Allow custom the active-dot element.
dotColor?: ?string,
// Allow custom the active-dot element.
activeDotColor?: ?string,
// Allow custom the active-dot element.
activeDotStyle?: ?Object,
// Autoplay
// Delay between auto play transitions (in second).
autoplayTimeout?: ?number,
// Cycle direction control.
autoplayDirection?: ?boolean,
// Control buttons
// Set to true make control buttons visible.
buttonWrapperStyle?: ?Object,
// Allow custom the next button.
nextButton?: ?Node,
// Allow custom the prev button.
prevButton?: ?Node,
// Supported ScrollResponder
// When animation begins after letting up
onScrollBeginDrag?: ?(event?: any, state?: any, context?: any) => void,
// Makes no sense why this occurs first during bounce
onMomentumScrollEnd?: ?(event?: any, state?: any, context?: any) => void,
// Immediately after onMomentumScrollEnd
onTouchStartCapture?: ?(event?: any, state?: any, context?: any) => void,
// Same, but bubble phase
onTouchStart?: ?(event?: any, state?: any, context?: any) => void,
// You could hold the touch start for a long time
onTouchEnd?: ?(event?: any, state?: any, context?: any) => void,
// When lifting up - you could pause forever before * lifting
onResponderRelease?: ?(event?: any, state?: any, context?: any) => void,
// If true, the scroll view stops on multiples of the scroll view's size when scrolling. This can be used for
// horizontal pagination.
pagingEnabled?: ?boolean,
// Set to true if you want to show horizontal scroll bar.
showsHorizontalScrollIndicator?: ?boolean,
// Set to true if you want to show vertical scroll bar.
showsVerticalScrollIndicator?: ?boolean,
// If true, the scroll view bounces when it reaches the end of the content if the content is larger then the
// scroll view along the axis of the scroll direction. If false, it disables all bouncing even if the
// alwaysBounce* props are true.
bounces?: ?boolean,
// If true, the scroll view scrolls to top when the status bar is tapped.
scrollsToTop?: ?boolean,
// If true, offscreen child views (whose overflow value is hidden) are removed from their native backing
// superview when offscreen. This canimprove scrolling performance on long lists.
removeClippedSubviews?: ?boolean,
// Set to true if you need adjust content insets automation.
automaticallyAdjustContentInsets?: ?boolean,
// Enables/Disables swiping
scrollEnabled?: ?boolean
|}>;
// eslint-disable-next-line no-undef
declare export default class Swiper extends Component<SwiperProps> {
scrollBy(index: number, animated?: boolean): void;
}
}

View File

@ -5,10 +5,11 @@
"react-native",
"ios"
],
"version": "1.5.13",
"version": "1.6.0-nightly.4",
"description": "Swiper component for React Native.",
"main": "index.js",
"scripts": {
"commit": "npx git-cz",
"start": "react-native start",
"lint": "standard | snazzy",
"update": "updtr",
@ -46,7 +47,7 @@
"url": "git+https://github.com/leecade/react-native-swiper.git"
},
"author": "",
"license": "ISC",
"license": "MIT",
"bugs": {
"url": "https://github.com/leecade/react-native-swiper/issues"
},
@ -54,11 +55,16 @@
"devDependencies": {
"babel-eslint": "^8.0.1",
"rimraf": "^2.5.4",
"snazzy": "^6.0.0",
"standard": "^10.0.3",
"snazzy": "^7.1.0",
"standard": "^14.2.0",
"updtr": "^2.0.0"
},
"dependencies": {
"prop-types": "^15.5.10"
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
}
}

View File

@ -11,7 +11,6 @@ import {
ScrollView,
Dimensions,
TouchableOpacity,
ViewPagerAndroid,
Platform,
ActivityIndicator
} from 'react-native'
@ -28,7 +27,7 @@ const styles = {
},
wrapperIOS: {
backgroundColor: 'transparent',
backgroundColor: 'transparent'
},
wrapperAndroid: {
@ -37,7 +36,7 @@ const styles = {
},
slide: {
backgroundColor: 'transparent',
backgroundColor: 'transparent'
},
pagination_x: {
@ -91,8 +90,7 @@ const styles = {
buttonText: {
fontSize: 50,
color: '#007aff',
fontFamily: 'Arial'
color: '#007aff'
}
}
@ -106,18 +104,13 @@ export default class extends Component {
static propTypes = {
horizontal: PropTypes.bool,
children: PropTypes.node.isRequired,
containerStyle: PropTypes.oneOfType([
PropTypes.object,
PropTypes.number,
]),
containerStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number]),
style: PropTypes.oneOfType([
PropTypes.object,
PropTypes.number,
PropTypes.array
]),
scrollViewStyle: PropTypes.oneOfType([
PropTypes.object,
PropTypes.number,
]),
scrollViewStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number]),
pagingEnabled: PropTypes.bool,
showsHorizontalScrollIndicator: PropTypes.bool,
showsVerticalScrollIndicator: PropTypes.bool,
@ -128,6 +121,7 @@ export default class extends Component {
showsPagination: PropTypes.bool,
showsButtons: PropTypes.bool,
disableNextButton: PropTypes.bool,
disablePrevButton: PropTypes.bool,
loadMinimal: PropTypes.bool,
loadMinimalSize: PropTypes.number,
loadMinimalLoader: PropTypes.element,
@ -137,8 +131,16 @@ export default class extends Component {
autoplayDirection: PropTypes.bool,
index: PropTypes.number,
renderPagination: PropTypes.func,
dotStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number]),
activeDotStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number]),
dotStyle: PropTypes.oneOfType([
PropTypes.object,
PropTypes.number,
PropTypes.array
]),
activeDotStyle: PropTypes.oneOfType([
PropTypes.object,
PropTypes.number,
PropTypes.array
]),
dotColor: PropTypes.string,
activeDotColor: PropTypes.string,
/**
@ -164,6 +166,7 @@ export default class extends Component {
showsPagination: true,
showsButtons: false,
disableNextButton: false,
disablePrevButton: false,
loop: true,
loadMinimal: false,
loadMinimalSize: 1,
@ -193,42 +196,66 @@ export default class extends Component {
autoplayTimer = null
loopJumpTimer = null
componentWillReceiveProps (nextProps) {
if (!nextProps.autoplay && this.autoplayTimer) clearTimeout(this.autoplayTimer)
this.setState(this.initState(nextProps, this.props.index !== nextProps.index))
componentWillReceiveProps(nextProps) {
if (!nextProps.autoplay && this.autoplayTimer)
clearTimeout(this.autoplayTimer)
if (nextProps.index === this.props.index) return
this.setState(
this.initState(nextProps, this.props.index !== nextProps.index)
)
}
componentDidMount () {
componentDidMount() {
this.autoplay()
}
componentWillUnmount () {
componentWillUnmount() {
this.autoplayTimer && clearTimeout(this.autoplayTimer)
this.loopJumpTimer && clearTimeout(this.loopJumpTimer)
}
componentWillUpdate (nextProps, nextState) {
componentWillUpdate(nextProps, nextState) {
// If the index has changed, we notify the parent via the onIndexChanged callback
if (this.state.index !== nextState.index) this.props.onIndexChanged(nextState.index)
if (this.state.index !== nextState.index)
this.props.onIndexChanged(nextState.index)
}
initState (props, updateIndex = false) {
componentDidUpdate(prevProps) {
// If autoplay props updated to true, autoplay immediately
if (this.props.autoplay && !prevProps.autoplay) {
this.autoplay()
}
if (this.props.children !== prevProps.children) {
this.setState(
this.initState({ ...this.props, index: this.state.index }, true)
)
}
}
initState(props, updateIndex = false) {
// set the current state
const state = this.state || { width: 0, height: 0, offset: { x: 0, y: 0 } }
const initState = {
autoplayEnd: false,
children: null,
loopJump: false,
offset: {}
}
initState.total = props.children ? props.children.length || 1 : 0
// Support Optional render page
initState.children = Array.isArray(props.children)
? props.children.filter(child => child)
: props.children
initState.total = initState.children ? initState.children.length || 1 : 0
if (state.total === initState.total && !updateIndex) {
// retain the index
initState.index = state.index
} else {
initState.index = initState.total > 1 ? Math.min(props.index, initState.total - 1) : 0
initState.index =
initState.total > 1 ? Math.min(props.index, initState.total - 1) : 0
}
// Default: horizontal
@ -238,40 +265,38 @@ export default class extends Component {
if (props.width) {
initState.width = props.width
} else if (this.state && this.state.width){
} else if (this.state && this.state.width) {
initState.width = this.state.width
} else {
initState.width = width;
initState.width = width
}
if (props.height) {
initState.height = props.height
} else if (this.state && this.state.height){
} else if (this.state && this.state.height) {
initState.height = this.state.height
} else {
initState.height = height;
initState.height = height
}
initState.offset[initState.dir] = initState.dir === 'y'
? height * props.index
: width * props.index
initState.offset[initState.dir] =
initState.dir === 'y' ? height * props.index : width * props.index
this.internals = {
...this.internals,
isScrolling: false
};
}
return initState
}
// include internals with state
fullState () {
fullState() {
return Object.assign({}, this.state, this.internals)
}
onLayout = (event) => {
onLayout = event => {
const { width, height } = event.nativeEvent.layout
const offset = this.internals.offset = {}
const offset = (this.internals.offset = {})
const state = { width, height }
if (this.state.total > 1) {
@ -279,25 +304,26 @@ export default class extends Component {
if (this.props.loop) {
setup++
}
offset[this.state.dir] = this.state.dir === 'y'
? height * setup
: width * setup
offset[this.state.dir] =
this.state.dir === 'y' ? height * setup : width * setup
}
// only update the offset in state if needed, updating offset while swiping
// causes some bad jumping / stuttering
if (!this.state.offset || width !== this.state.width || height !== this.state.height) {
if (
!this.state.offset ||
width !== this.state.width ||
height !== this.state.height
) {
state.offset = offset
}
// related to https://github.com/leecade/react-native-swiper/issues/570
// contentOffset is not working in react 0.48.x so we need to use scrollTo
// to emulate offset.
if (Platform.OS === 'ios') {
if (this.initialRender && this.state.total > 1) {
this.scrollView.scrollTo({...offset, animated: false})
this.initialRender = false;
}
if (this.initialRender && this.state.total > 1) {
this.scrollView.scrollTo({ ...offset, animated: false })
this.initialRender = false
}
this.setState(state)
@ -307,27 +333,35 @@ export default class extends Component {
if (!this.state.loopJump) return
const i = this.state.index + (this.props.loop ? 1 : 0)
const scrollView = this.scrollView
this.loopJumpTimer = setTimeout(() => scrollView.setPageWithoutAnimation &&
scrollView.setPageWithoutAnimation(i), 50)
this.loopJumpTimer = setTimeout(
() =>
scrollView.setPageWithoutAnimation &&
scrollView.setPageWithoutAnimation(i),
50
)
}
/**
* Automatic rolling
*/
autoplay = () => {
if (!Array.isArray(this.props.children) ||
if (
!Array.isArray(this.state.children) ||
!this.props.autoplay ||
this.internals.isScrolling ||
this.state.autoplayEnd) return
this.state.autoplayEnd
)
return
this.autoplayTimer && clearTimeout(this.autoplayTimer)
this.autoplayTimer = setTimeout(() => {
if (!this.props.loop && (
this.props.autoplayDirection
? this.state.index === this.state.total - 1
: this.state.index === 0
)
) return this.setState({ autoplayEnd: true })
if (
!this.props.loop &&
(this.props.autoplayDirection
? this.state.index === this.state.total - 1
: this.state.index === 0)
)
return this.setState({ autoplayEnd: true })
this.scrollBy(this.props.autoplayDirection ? 1 : -1)
}, this.props.autoplayTimeout * 1000)
@ -340,7 +374,8 @@ export default class extends Component {
onScrollBegin = e => {
// update scroll state
this.internals.isScrolling = true
this.props.onScrollBeginDrag && this.props.onScrollBeginDrag(e, this.fullState(), this)
this.props.onScrollBeginDrag &&
this.props.onScrollBeginDrag(e, this.fullState(), this)
}
/**
@ -354,9 +389,13 @@ export default class extends Component {
// making our events coming from android compatible to updateIndex logic
if (!e.nativeEvent.contentOffset) {
if (this.state.dir === 'x') {
e.nativeEvent.contentOffset = {x: e.nativeEvent.position * this.state.width}
e.nativeEvent.contentOffset = {
x: e.nativeEvent.position * this.state.width
}
} else {
e.nativeEvent.contentOffset = {y: e.nativeEvent.position * this.state.height}
e.nativeEvent.contentOffset = {
y: e.nativeEvent.position * this.state.height
}
}
}
@ -365,7 +404,8 @@ export default class extends Component {
this.loopJump()
// if `onMomentumScrollEnd` registered will be called here
this.props.onMomentumScrollEnd && this.props.onMomentumScrollEnd(e, this.fullState(), this)
this.props.onMomentumScrollEnd &&
this.props.onMomentumScrollEnd(e, this.fullState(), this)
})
}
@ -375,14 +415,16 @@ export default class extends Component {
*/
onScrollEndDrag = e => {
const { contentOffset } = e.nativeEvent
const { horizontal, children } = this.props
const { index } = this.state
const { horizontal } = this.props
const { children, index } = this.state
const { offset } = this.internals
const previousOffset = horizontal ? offset.x : offset.y
const newOffset = horizontal ? contentOffset.x : contentOffset.y
if (previousOffset === newOffset &&
(index === 0 || index === children.length - 1)) {
if (
previousOffset === newOffset &&
(index === 0 || index === children.length - 1)
) {
this.internals.isScrolling = false
}
}
@ -394,7 +436,41 @@ export default class extends Component {
*/
updateIndex = (offset, dir, cb) => {
const state = this.state
// Android ScrollView will not scrollTo certain offset when props change
const callback = async () => {
cb()
if (Platform.OS === 'android') {
if (this.state.index === 0) {
this.props.horizontal
? this.scrollView.scrollTo({
x: state.width,
y: 0,
animated: false
})
: this.scrollView.scrollTo({
x: 0,
y: state.height,
animated: false
})
} else if (this.state.index === this.state.total - 1) {
this.props.horizontal
? this.scrollView.scrollTo({
x: state.width * this.state.total,
y: 0,
animated: false
})
: this.scrollView.scrollTo({
x: 0,
y: state.height * this.state.total,
animated: false
})
}
}
}
let index = state.index
if (!this.internals.offset)
// Android not setting this onLayout first? https://github.com/leecade/react-native-swiper/issues/582
this.internals.offset = {}
const diff = offset[dir] - this.internals.offset[dir]
const step = dir === 'x' ? state.width : state.height
let loopJump = false
@ -436,14 +512,14 @@ export default class extends Component {
newState.offset = { x: 0, y: 0 }
newState.offset[dir] = offset[dir] + 1
this.setState(newState, () => {
this.setState({ offset: offset }, cb)
this.setState({ offset: offset }, callback)
})
} else {
newState.offset = offset
this.setState(newState, cb)
this.setState(newState, callback)
}
} else {
this.setState(newState, cb)
this.setState(newState, callback)
}
}
@ -462,11 +538,49 @@ export default class extends Component {
if (state.dir === 'x') x = diff * state.width
if (state.dir === 'y') y = diff * state.height
if (Platform.OS !== 'ios') {
this.scrollView && this.scrollView[animated ? 'setPage' : 'setPageWithoutAnimation'](diff)
} else {
this.scrollView && this.scrollView.scrollTo({ x, y, animated })
this.scrollView && this.scrollView.scrollTo({ x, y, animated })
// update scroll state
this.internals.isScrolling = true
this.setState({
autoplayEnd: false
})
// trigger onScrollEnd manually in android
if (!animated || Platform.OS !== 'ios') {
setImmediate(() => {
this.onScrollEnd({
nativeEvent: {
position: diff
}
})
})
}
}
/**
* Scroll to index
* @param {number} index page
* @param {bool} animated
*/
scrollTo = (index, animated = true) => {
if (
this.internals.isScrolling ||
this.state.total < 2 ||
index == this.state.index
)
return
const state = this.state
const diff = this.state.index + (index - this.state.index)
let x = 0
let y = 0
if (state.dir === 'x') x = diff * state.width
if (state.dir === 'y') y = diff * state.height
this.scrollView && this.scrollView.scrollTo({ x, y, animated })
// update scroll state
this.internals.isScrolling = true
@ -502,13 +616,14 @@ export default class extends Component {
for (let prop in props) {
// if(~scrollResponders.indexOf(prop)
if (typeof props[prop] === 'function' &&
if (
typeof props[prop] === 'function' &&
prop !== 'onMomentumScrollEnd' &&
prop !== 'renderPagination' &&
prop !== 'onScrollBeginDrag'
) {
let originResponder = props[prop]
overrides[prop] = (e) => originResponder(e, this.fullState(), this)
overrides[prop] = e => originResponder(e, this.fullState(), this)
}
}
@ -520,59 +635,79 @@ export default class extends Component {
* @return {object} react-dom
*/
renderPagination = () => {
// By default, dots only show when `total` >= 2
// By default, dots only show when `total` >= 2
if (this.state.total <= 1) return null
let dots = []
const ActiveDot = this.props.activeDot || <View style={[{
backgroundColor: this.props.activeDotColor || '#007aff',
width: 8,
height: 8,
borderRadius: 4,
marginLeft: 3,
marginRight: 3,
marginTop: 3,
marginBottom: 3
}, this.props.activeDotStyle]} />
const Dot = this.props.dot || <View style={[{
backgroundColor: this.props.dotColor || 'rgba(0,0,0,.2)',
width: 8,
height: 8,
borderRadius: 4,
marginLeft: 3,
marginRight: 3,
marginTop: 3,
marginBottom: 3
}, this.props.dotStyle ]} />
const ActiveDot = this.props.activeDot || (
<View
style={[
{
backgroundColor: this.props.activeDotColor || '#007aff',
width: 8,
height: 8,
borderRadius: 4,
marginLeft: 3,
marginRight: 3,
marginTop: 3,
marginBottom: 3
},
this.props.activeDotStyle
]}
/>
)
const Dot = this.props.dot || (
<View
style={[
{
backgroundColor: this.props.dotColor || 'rgba(0,0,0,.2)',
width: 8,
height: 8,
borderRadius: 4,
marginLeft: 3,
marginRight: 3,
marginTop: 3,
marginBottom: 3
},
this.props.dotStyle
]}
/>
)
for (let i = 0; i < this.state.total; i++) {
dots.push(i === this.state.index
? React.cloneElement(ActiveDot, {key: i})
: React.cloneElement(Dot, {key: i})
dots.push(
i === this.state.index
? React.cloneElement(ActiveDot, { key: i })
: React.cloneElement(Dot, { key: i })
)
}
return (
<View pointerEvents='none' style={[styles['pagination_' + this.state.dir], this.props.paginationStyle]}>
<View
pointerEvents="none"
style={[
styles['pagination_' + this.state.dir],
this.props.paginationStyle
]}
>
{dots}
</View>
)
}
renderTitle = () => {
const child = this.props.children[this.state.index]
const child = this.state.children[this.state.index]
const title = child && child.props && child.props.title
return title
? (<View style={styles.title}>
{this.props.children[this.state.index].props.title}
</View>)
: null
return title ? (
<View style={styles.title}>
{this.state.children[this.state.index].props.title}
</View>
) : null
}
renderNextButton = () => {
let button = null
if (this.props.loop ||
this.state.index !== this.state.total - 1) {
if (this.props.loop || this.state.index !== this.state.total - 1) {
button = this.props.nextButton || <Text style={styles.buttonText}></Text>
}
@ -581,9 +716,7 @@ export default class extends Component {
onPress={() => button !== null && this.scrollBy(1)}
disabled={this.props.disableNextButton}
>
<View>
{button}
</View>
<View>{button}</View>
</TouchableOpacity>
)
}
@ -596,20 +729,28 @@ export default class extends Component {
}
return (
<TouchableOpacity onPress={() => button !== null && this.scrollBy(-1)}>
<View>
{button}
</View>
<TouchableOpacity
onPress={() => button !== null && this.scrollBy(-1)}
disabled={this.props.disablePrevButton}
>
<View>{button}</View>
</TouchableOpacity>
)
}
renderButtons = () => {
return (
<View pointerEvents='box-none' style={[styles.buttonWrapper, {
width: this.state.width,
height: this.state.height
}, this.props.buttonWrapperStyle]}>
<View
pointerEvents="box-none"
style={[
styles.buttonWrapper,
{
width: this.state.width,
height: this.state.height
},
this.props.buttonWrapperStyle
]}
>
{this.renderPrevButton()}
{this.renderNextButton()}
</View>
@ -617,34 +758,35 @@ export default class extends Component {
}
refScrollView = view => {
this.scrollView = view;
this.scrollView = view
}
onPageScrollStateChanged = state => {
switch (state) {
case 'dragging':
return this.onScrollBegin()
case 'idle':
case 'settling':
if (this.props.onTouchEnd) this.props.onTouchEnd()
}
}
renderScrollView = pages => {
if (Platform.OS === 'ios') {
return (
<ScrollView ref={this.refScrollView}
{...this.props}
{...this.scrollViewPropOverrides()}
contentContainerStyle={[styles.wrapperIOS, this.props.style]}
contentOffset={this.state.offset}
onScrollBeginDrag={this.onScrollBegin}
onMomentumScrollEnd={this.onScrollEnd}
onScrollEndDrag={this.onScrollEndDrag}
style={this.props.scrollViewStyle}>
{pages}
</ScrollView>
)
}
return (
<ViewPagerAndroid ref={this.refScrollView}
<ScrollView
ref={this.refScrollView}
{...this.props}
initialPage={this.props.loop ? this.state.index + 1 : this.state.index}
onPageSelected={this.onScrollEnd}
key={pages.length}
style={[styles.wrapperAndroid, this.props.style]}>
{...this.scrollViewPropOverrides()}
contentContainerStyle={[styles.wrapperIOS, this.props.style]}
contentOffset={this.state.offset}
onScrollBeginDrag={this.onScrollBegin}
onMomentumScrollEnd={this.onScrollEnd}
onScrollEndDrag={this.onScrollEndDrag}
style={this.props.scrollViewStyle}
>
{pages}
</ViewPagerAndroid>
</ScrollView>
)
}
@ -652,17 +794,9 @@ export default class extends Component {
* Default render
* @return {object} react-dom
*/
render () {
const state = this.state
const props = this.props
render() {
const { index, total, width, height, children } = this.state
const {
index,
total,
width,
height
} = this.state;
const {
children,
containerStyle,
loop,
loadMinimal,
@ -670,14 +804,14 @@ export default class extends Component {
loadMinimalLoader,
renderPagination,
showsButtons,
showsPagination,
} = this.props;
showsPagination
} = this.props
// let dir = state.dir
// let key = 0
const loopVal = loop ? 1 : 0
let pages = []
const pageStyle = [{width: width, height: height}, styles.slide]
const pageStyle = [{ width: width, height: height }, styles.slide]
const pageStyleLoading = {
width,
height,
@ -697,9 +831,15 @@ export default class extends Component {
pages = pages.map((page, i) => {
if (loadMinimal) {
if (i >= (index + loopVal - loadMinimalSize) &&
i <= (index + loopVal + loadMinimalSize)) {
return <View style={pageStyle} key={i}>{children[page]}</View>
if (
i >= index + loopVal - loadMinimalSize &&
i <= index + loopVal + loadMinimalSize
) {
return (
<View style={pageStyle} key={i}>
{children[page]}
</View>
)
} else {
return (
<View style={pageStyleLoading} key={i}>
@ -708,19 +848,28 @@ export default class extends Component {
)
}
} else {
return <View style={pageStyle} key={i}>{children[page]}</View>
return (
<View style={pageStyle} key={i}>
{children[page]}
</View>
)
}
})
} else {
pages = <View style={pageStyle} key={0}>{children}</View>
pages = (
<View style={pageStyle} key={0}>
{children}
</View>
)
}
return (
<View style={[styles.container, containerStyle]} onLayout={this.onLayout}>
{this.renderScrollView(pages)}
{showsPagination && (renderPagination
? renderPagination(index, total, this)
: this.renderPagination())}
{showsPagination &&
(renderPagination
? renderPagination(index, total, this)
: this.renderPagination())}
{this.renderTitle()}
{showsButtons && this.renderButtons()}
</View>

1763
yarn.lock

File diff suppressed because it is too large Load Diff