@ohos-ports/react-native-scrollable-mixin 0.0.0-stage → 1.0.1-beta.1
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.
- package/.flowconfig +7 -0
- package/LICENSE +22 -0
- package/README.md +113 -2
- package/ScrollableMixin.js +15 -0
- package/package.json +26 -4
package/.flowconfig
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 650 Industries
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
CHANGED
|
@@ -1,3 +1,114 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ScrollableMixin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
ScrollableMixin lets your scrollable React Native components conform to a standard interface, making it easier to compose components. This lets you compose different types of ScrollView-like components while preserving the `ScrollView` API, including methods like `scrollTo`.
|
|
4
|
+
|
|
5
|
+
See [react-native-scrollable-decorator](https://github.com/exponentjs/react-native-scrollable-decorator) for the decorator version of this mixin.
|
|
6
|
+
|
|
7
|
+
[](https://nodei.co/npm/react-native-scrollable-mixin/)
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
```
|
|
11
|
+
npm install @ohos-ports/react-native-scrollable-mixin
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
Add ScrollableMixin to your scrollable React components and implement `getScrollResponder()`, which must return the underlying scrollable component's scroll responder.
|
|
17
|
+
|
|
18
|
+
## With JavaScript classes
|
|
19
|
+
|
|
20
|
+
Use `Object.assign` to copy ScrollableMixin's functions to your class's prototype as instance methods:
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
class InfiniteScrollView extends React.Component {
|
|
24
|
+
static propTypes = {
|
|
25
|
+
...ScrollView.propTypes,
|
|
26
|
+
renderScrollComponent: PropTypes.func.isRequired
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* IMPORTANT: You must return the scroll responder of the underlying
|
|
31
|
+
* scrollable component from getScrollResponder() when using ScrollableMixin.
|
|
32
|
+
*/
|
|
33
|
+
getScrollResponder() {
|
|
34
|
+
return this._scrollView.getScrollResponder();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
setNativeProps(props) {
|
|
38
|
+
this._scrollView.setNativeProps(props);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
render() {
|
|
42
|
+
let { renderScrollComponent, ...props } = this.props;
|
|
43
|
+
return React.cloneElement(renderScrollComponent(props), {
|
|
44
|
+
ref: component => { this._scrollView = component; },
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Mix in ScrollableMixin's methods as instance methods
|
|
50
|
+
Object.assign(InfiniteScrollView.prototype, ScrollableMixin);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### With `React.createClass`
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
let ScrollableMixin = require('@ohos-ports/react-native-scrollable-mixin');
|
|
57
|
+
|
|
58
|
+
let InfiniteScrollView = React.createClass({
|
|
59
|
+
mixins: [ScrollableMixin],
|
|
60
|
+
|
|
61
|
+
propTypes: {
|
|
62
|
+
...ScrollView.propTypes,
|
|
63
|
+
renderScrollComponent: PropTypes.func.isRequired,
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* IMPORTANT: You must return the scroll responder of the underlying
|
|
68
|
+
* scrollable component from getScrollResponder() when using ScrollableMixin.
|
|
69
|
+
*/
|
|
70
|
+
getScrollResponder() {
|
|
71
|
+
return this._scrollView.getScrollResponder();
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
setNativeProps(props) {
|
|
75
|
+
this._scrollView.setNativeProps(props);
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
render() {
|
|
79
|
+
var {
|
|
80
|
+
renderScrollComponent,
|
|
81
|
+
...props
|
|
82
|
+
} = this.props;
|
|
83
|
+
return React.cloneElement(renderScrollComponent(props), {
|
|
84
|
+
ref: component => { this._scrollView = component; },
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Features
|
|
91
|
+
|
|
92
|
+
By mixing in ScrollableMixin, your custom component gets the `ScrollView` API. For example:
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
class App extends React.Component {
|
|
96
|
+
render() {
|
|
97
|
+
return (
|
|
98
|
+
<ListView
|
|
99
|
+
ref={component => this._scrollView = component}
|
|
100
|
+
renderScrollView={props => <InfiniteScrollView {...props} />}
|
|
101
|
+
dataSource={...}
|
|
102
|
+
renderRow={...}
|
|
103
|
+
/>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
_scrollToTop() {
|
|
108
|
+
// By having all scrollable components conform to ScrollableMixin's
|
|
109
|
+
// standard, calling `scrollTo` on your top-level scrollable component will
|
|
110
|
+
// successfully scroll the underlying scroll view.
|
|
111
|
+
this._scrollView.scrollTo(0, 0);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
let ScrollableMixin = {
|
|
2
|
+
getInnerViewNode() {
|
|
3
|
+
return this.getScrollResponder().getInnerViewNode();
|
|
4
|
+
},
|
|
5
|
+
|
|
6
|
+
scrollTo(destY, destX) {
|
|
7
|
+
this.getScrollResponder().scrollTo(destY, destX);
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
scrollWithoutAnimationTo(destY, destX) {
|
|
11
|
+
this.getScrollResponder().scrollWithoutAnimationTo(destY, destX);
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
module.exports = ScrollableMixin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohos-ports/react-native-scrollable-mixin",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1-beta.1",
|
|
4
|
+
"description": "A standard interface for your scrollable React Native components, making it easier to compose components. (HarmonyOS port: Flow annotations stripped so the package loads under plain Node.js)",
|
|
5
|
+
"main": "ScrollableMixin.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "jest"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/ohos-ports/ohos-ports.git",
|
|
12
|
+
"directory": "ports/react-native-scrollable-mixin/1.0.1"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"react-native",
|
|
16
|
+
"scroll",
|
|
17
|
+
"scrollview",
|
|
18
|
+
"mixin",
|
|
19
|
+
"ohos-ports",
|
|
20
|
+
"harmonyos"
|
|
21
|
+
],
|
|
22
|
+
"author": "James Ide",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/ohos-ports/ohos-ports/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/ohos-ports/ohos-ports/tree/main/ports/react-native-scrollable-mixin/1.0.1"
|
|
28
|
+
}
|