Skip to content

Commit 24ce1e6

Browse files
authored
Refactors (#30)
1 parent 58f057b commit 24ce1e6

File tree

3 files changed

+26
-31
lines changed

3 files changed

+26
-31
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ module.exports = {
6161
'react/prefer-stateless-function': 1,
6262
'react/display-name': 0,
6363
'react/prefer-stateless-function': 'off',
64+
'react/sort-comp': 'off',
6465
},
6566
globals: {
6667
it: false,

README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,26 +88,26 @@ const styles = StyleSheet.create({
8888

8989
## Props
9090

91-
| Prop | Default | Type | Description |
91+
| Prop | Default | Type | Description |
9292
| :--------------------- | :-----------------------------------------------: | :-------------------: | :------------------------------------------------------------------- |
93-
| data | _not required if children is used_ | `array` | Data to use in renderItem |
94-
| children | - | `node` | Children elements |
95-
| renderItem | _not required if children is used_ | `func` | Takes an item from data and renders it into the list |
96-
| onMomentumScrollEnd | - | `func` | Called after scroll end and the first parameter is the current index |
97-
| vertical | false | `bool` | Show vertical swiper |
98-
| index | 0 | `number` | Index to start |
99-
| renderAll | false | `bool` | Render all the items before display it |
93+
| data | _not required if children is used_ | `array` | Data to use in renderItem |
94+
| children | - | `node` | Children elements |
95+
| renderItem | _not required if children is used_ | `func` | Takes an item from data and renders it into the list |
96+
| onMomentumScrollEnd | - | `func` | Called after scroll end and the first parameter is the current index |
97+
| vertical | false | `bool` | Show vertical swiper |
98+
| index | 0 | `number` | Index to start |
99+
| renderAll | false | `bool` | Render all the items before display it |
100100
| **Pagination** |
101-
| showPagination | false | `bool` | Show pagination |
102-
| paginationDefaultColor | gray | `string` | Pagination color |
103-
| paginationActiveColor | white | `string` | Pagination color |
104-
| paginationStyle | {} | `ViewPropTypes.style` | Style object for container |
105-
| paginationStyleItem | {} | `ViewPropTypes.style` | Style object for item (dot) |
106-
| PaginationComponent | [Component](./src/components/Pagination/index.js) | `node` | Overwrite Pagination component |
101+
| showPagination | false | `bool` | Show pagination |
102+
| paginationDefaultColor | gray | `string` | Pagination color |
103+
| paginationActiveColor | white | `string` | Pagination color |
104+
| paginationStyle | {} | `ViewPropTypes.style` | Style object for container |
105+
| paginationStyleItem | {} | `ViewPropTypes.style` | Style object for item (dot) |
106+
| PaginationComponent | [Component](./src/components/Pagination/index.js) | `node` | Overwrite Pagination component |
107107
| **Autoplay** |
108-
| autoplay | false | `bool` | Change index automatically |
109-
| autoplayDelay | 3 | `number` | Delay between every page |
110-
| autoplayLoop | false | `bool` | Continue playing after reach end |
108+
| autoplay | false | `bool` | Change index automatically |
109+
| autoplayDelay | 3 | `number` | Delay between every page |
110+
| autoplayLoop | false | `bool` | Continue playing after reach end |
111111

112112
**More props**
113113

@@ -118,10 +118,10 @@ autoplayDirection: PropTypes.bool.isRequired, -->
118118

119119
## Functions
120120

121-
| Function name | Use |
122-
|-----------------|----------------------------------------------------|
123-
| scrollToIndex | Forces the scroll of the swiper to a precise index |
124-
| getCurrentIndex | Returns the current index inside the swiper |
121+
| Name | Params | Use |
122+
| :-------------- | :---------------------------------- | :------------------------------------------------- |
123+
| scrollToIndex | (index: `number`, animated: `bool`) | Forces the scroll of the swiper to a precise index |
124+
| getCurrentIndex | - | Returns the current index inside the swiper |
125125

126126

127127
## Limitations

src/components/SwiperFlatList/index.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ export default class SwiperFlatList extends PureComponent {
9090
this._initialNumToRender = renderAll ? this._data.length : 1;
9191
};
9292

93-
getCurrentIndex() {
94-
return this.state.paginationIndex;
95-
}
96-
9793
_autoplay = index => {
9894
const { autoplayDelay, autoplayLoop } = this.props;
9995
if (this.autoplayTimer) {
@@ -156,13 +152,11 @@ export default class SwiperFlatList extends PureComponent {
156152

157153
_keyExtractor = (item, index) => index.toString();
158154

159-
renderChildren = ({ item }) => item;
155+
getCurrentIndex = () => this.state.paginationIndex;
160156

161-
// additional functions for user
162-
scrollToIndex(index) {
163-
this.setState({ paginationIndex: index });
164-
this.flatListRef.scrollToIndex({ animated: false, index });
165-
}
157+
scrollToIndex = (...args) => this._scrollToIndex(...args);
158+
159+
renderChildren = ({ item }) => item;
166160

167161
render() {
168162
const {

0 commit comments

Comments
 (0)