Skip to content

Commit c9d7495

Browse files
committed
first commit
0 parents  commit c9d7495

File tree

7 files changed

+299
-0
lines changed

7 files changed

+299
-0
lines changed

.eslintrc

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"root": true,
3+
"parser": "babel-eslint",
4+
"env": {
5+
"es6": true,
6+
"node": true,
7+
"jest": true
8+
},
9+
"extends": ["airbnb", "plugin:jsx-a11y/recommended"],
10+
"plugins": [
11+
"flowtype",
12+
"react",
13+
"react-native",
14+
"jsx-a11y"
15+
],
16+
"globals": {
17+
"__DEV__": true,
18+
"__dirname": false,
19+
"__fbBatchedBridgeConfig": false,
20+
"alert": false,
21+
"cancelAnimationFrame": false,
22+
"cancelIdleCallback": false,
23+
"clearImmediate": true,
24+
"clearInterval": false,
25+
"clearTimeout": false,
26+
"console": false,
27+
"document": false,
28+
"escape": false,
29+
"Event": false,
30+
"EventTarget": false,
31+
"exports": false,
32+
"fetch": false,
33+
"FormData": false,
34+
"global": false,
35+
"jest": false,
36+
"Map": true,
37+
"module": false,
38+
"navigator": false,
39+
"process": false,
40+
"Promise": true,
41+
"requestAnimationFrame": true,
42+
"requestIdleCallback": true,
43+
"require": false,
44+
"Set": true,
45+
"setImmediate": true,
46+
"setInterval": false,
47+
"setTimeout": false,
48+
"window": false,
49+
"XMLHttpRequest": false,
50+
"pit": false,
51+
"type": true
52+
},
53+
"rules": {
54+
"react/jsx-filename-extension": [1, {"extensions": [".js"]}],
55+
"no-underscore-dangle": 0,
56+
"react/forbid-prop-types": 0,
57+
"max-len": 0,
58+
"no-console": 0,
59+
"object-curly-newline": 0,
60+
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }]
61+
}
62+
}

.gitignore

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# Xcode
6+
#
7+
build/
8+
*.pbxuser
9+
!default.pbxuser
10+
*.mode1v3
11+
!default.mode1v3
12+
*.mode2v3
13+
!default.mode2v3
14+
*.perspectivev3
15+
!default.perspectivev3
16+
xcuserdata
17+
*.xccheckout
18+
*.moved-aside
19+
DerivedData
20+
*.hmap
21+
*.ipa
22+
*.xcuserstate
23+
project.xcworkspace
24+
25+
# Android/IntelliJ
26+
#
27+
build/
28+
.idea
29+
.gradle
30+
local.properties
31+
*.properties.sample
32+
*.iml
33+
34+
# node.js
35+
#
36+
node_modules/
37+
npm-debug.log
38+
yarn-error.log
39+
40+
# BUCK
41+
buck-out/
42+
\.buckd/
43+
*.keystore
44+
45+
# fastlane
46+
#
47+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
48+
# screenshots whenever they are needed.
49+
# For more information about the recommended setup visit:
50+
# https://docs.fastlane.tools/best-practices/source-control/
51+
52+
*/fastlane/report.xml
53+
*/fastlane/Preview.html
54+
*/fastlane/screenshots
55+
56+
# Bundle artifact
57+
*.jsbundle
58+
59+
# IDE
60+
.vscode
61+
62+
# assets
63+
# assets/*.psd
64+
65+
# js
66+
*.copy.js

.npmignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
examples
2+
.idea
3+
node_modules
4+
npm-debug.log
5+
.vscode

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Muhamad Rizal Ibnu Abdulah
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.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# react-native-scroll-up
2+
A React Native component to add custom button for scrolling back to top

index.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// @flow
2+
import * as React from 'react';
3+
import {
4+
TouchableOpacity,
5+
Text,
6+
Image,
7+
StyleSheet,
8+
} from 'react-native';
9+
10+
type Props = {
11+
radius: boolean,
12+
icon: React.Element,
13+
text: string,
14+
root: React.Ref,
15+
borderRadius: number,
16+
backgroundColor: string,
17+
color: string,
18+
fontSize: number,
19+
width: number,
20+
height: number,
21+
right: number,
22+
bottom: number,
23+
refTo: string,
24+
type: string,
25+
customTextStyle: Object,
26+
customImageStyle: Object,
27+
};
28+
29+
const scrollUpImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANEAAADRCAMAAABl5KfdAAAAMFBMVEX///9mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmambAcKAAAAD3RSTlMAESIzRFVmd4iZqrvM3e5GKvWZAAAIl0lEQVR4Ae2dSZLDOg5EOc8g73/bXnT0XzSKNtNOqVQRP/e29ZQACMkczJWyPqRcmqz/SVrJKXhr/pysC6m0ITKX1hQZraTg/gqYi6XLOpH0Et3TaVIdC5PU9FQqG8pYn2mUYB+HE6usbyQtPgkqbHAwzRoekjtZF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TRWEt7XTUs+ywDPY+058ywD4M6mz99Ma2Xa7amMM0EIieQ4z0RIzfJLKxAuA85K/NwWIGJnIJk0HQsIit7GcslNSvzGr8+ws2ORcslPfWMpQMNecI4YfqLeTKxBAA/eQKu79p+NLGdztCM7A/M8Ppwplt57TY7XeCT+mYl88c9MJJxryRf1XEva2aP0U7jb/efDQsLPh6UH8ZJwC1AQDpBCAjKTqnLD0dGPOAv73/PKkTPl02VA6dWZ8v+e+4/t3NI8P4FUmBNGQmQ3leq5PHXtNAO98mzUeL8U2tpqOHLxaWuvHg1Dsa+9Gr+05vVCkr+9gy4LtGkmvylR6sl+HgGpr1cSf0vjqDRb/ATKpaYKz22tcZrrDVTP2O30ub/9zmgulGvrraTlYE8sD7nJeqvmzLWKsg40R83B2x2LD7mOuQ4k8cbHsAMu6a3mlGLwznkfYkq51L5hAdphtnxf96h7c5fiuIFnEAMO7/f5kmRuls1yJU/mJxCfic/Dl01j8TUSlwfv/7lqwfy2HBp8/Baer1CFgVODeY5shKEUjjUPkw1lfIgzCgmHL5e2Dei+pY3OPFsuli5nkdbLc2kUVkil9SFzaU2R3koKzvw9WRdizrX/wzVaSVE9N3H1HxTThThvjywSAAAAAElFTkSuQmCC';
30+
31+
const styles = StyleSheet.create({
32+
wrapper: {
33+
position: 'absolute',
34+
flex: 1,
35+
justifyContent: 'center',
36+
alignItems: 'center',
37+
},
38+
});
39+
40+
export default class ScrollUp extends React.Component<Props> {
41+
static defaultProps = {
42+
radius: true,
43+
backgroundColor: 'transparent',
44+
width: 40,
45+
height: 40,
46+
color: '#fff',
47+
fontSize: 12,
48+
icon: null,
49+
right: 60,
50+
bottom: 150,
51+
borderRadius: 50,
52+
text: 'Scroll Up',
53+
imageUri: scrollUpImage,
54+
customTextStyle: {},
55+
customImageStyle: {},
56+
};
57+
58+
handleOnPress = () => {
59+
if (this.props.refTo === 'ListView' || this.props.refTo === 'ScrollView') {
60+
this.props.root.scrollTo({ x: 0, y: 0, animated: true });
61+
}
62+
if (this.props.refTo === 'FlatList') {
63+
this.props.root.scrollToOffset({ offset: 0, animated: true });
64+
}
65+
if (this.props.refTo === 'SectionList') {
66+
this.props.root.scrollToLocation({ itemIndex: 0, sectionIndex: 0 });
67+
}
68+
}
69+
70+
render = () => (
71+
<TouchableOpacity
72+
onPress={() => this.handleOnPress()}
73+
style={[
74+
styles.wrapper,
75+
{
76+
width: this.props.width,
77+
height: this.props.height,
78+
right: this.props.right,
79+
bottom: this.props.bottom,
80+
backgroundColor: this.props.backgroundColor,
81+
borderRadius: this.props.radius ? this.props.borderRadius : 0,
82+
},
83+
]}
84+
>
85+
{this.props.type === 'icon' && { ...this.props.icon }}
86+
{this.props.type === 'text' &&
87+
<Text
88+
style={[
89+
{
90+
textAlign: 'center',
91+
color: this.props.color,
92+
fontSize: this.props.fontSize,
93+
},
94+
this.props.customTextStyle,
95+
]}
96+
>
97+
{this.props.text}
98+
</Text>}
99+
{this.props.type === 'image' &&
100+
<Image
101+
style={[
102+
{
103+
width: this.props.width,
104+
height: this.props.height,
105+
},
106+
this.props.customImageStyle,
107+
]}
108+
source={{ uri: this.props.imageUri }}
109+
/>}
110+
</TouchableOpacity>
111+
);
112+
}

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "react-native-scroll-up",
3+
"version": "0.1.0",
4+
"description": "A React Native component to add custom button for scrolling back to top",
5+
"main": "index.js",
6+
"directories": {
7+
"example": "example"
8+
},
9+
"scripts": {
10+
"test": "echo \"Error: no test specified\" && exit 1"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/rizalibnu/react-native-scroll-up.git"
15+
},
16+
"keywords": [
17+
"react-native",
18+
"scrollup",
19+
"scrolltotop"
20+
],
21+
"author": "Rizal Ibnu <hello@rizalibnu.com>",
22+
"license": "MIT",
23+
"bugs": {
24+
"url": "https://github.com/rizalibnu/react-native-scroll-up/issues"
25+
},
26+
"homepage": "https://github.com/rizalibnu/react-native-scroll-up#readme",
27+
"devDependencies": {
28+
"eslint-config-airbnb": "^16.1.0",
29+
"eslint-plugin-flowtype": "^2.46.1"
30+
}
31+
}

0 commit comments

Comments
 (0)