├── .flowconfig
├── .gitignore
├── .tern-project
├── .watchmanconfig
├── LICENSE
├── index.js
├── js
├── components
│ └── example.js
├── swipe-actions.js
└── util.js
├── package.json
├── readme.md
└── swipe-actions.gif
/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 |
3 | # We fork some components by platform.
4 | .*/*.web.js
5 | .*/*.android.js
6 |
7 | # Some modules have their own node_modules with overlap
8 | .*/node_modules/node-haste/.*
9 |
10 | # Ugh
11 | .*/node_modules/babel.*
12 | .*/node_modules/babylon.*
13 | .*/node_modules/invariant.*
14 |
15 | # Ignore react and fbjs where there are overlaps, but don't ignore
16 | # anything that react-native relies on
17 | .*/node_modules/fbjs/lib/Map.js
18 | .*/node_modules/fbjs/lib/Promise.js
19 | .*/node_modules/fbjs/lib/fetch.js
20 | .*/node_modules/fbjs/lib/ExecutionEnvironment.js
21 | .*/node_modules/fbjs/lib/isEmpty.js
22 | .*/node_modules/fbjs/lib/crc32.js
23 | .*/node_modules/fbjs/lib/ErrorUtils.js
24 |
25 | # Flow has a built-in definition for the 'react' module which we prefer to use
26 | # over the currently-untyped source
27 | .*/node_modules/react/react.js
28 | .*/node_modules/react/lib/React.js
29 | .*/node_modules/react/lib/ReactDOM.js
30 |
31 | # Ignore commoner tests
32 | .*/node_modules/commoner/test/.*
33 |
34 | # See https://github.com/facebook/flow/issues/442
35 | .*/react-tools/node_modules/commoner/lib/reader.js
36 |
37 | # Ignore jest
38 | .*/node_modules/jest-cli/.*
39 |
40 | # Ignore Website
41 | .*/website/.*
42 |
43 | [include]
44 |
45 | [libs]
46 | node_modules/react-native/Libraries/react-native/react-native-interface.js
47 |
48 | [options]
49 | module.system=haste
50 |
51 | munge_underscores=true
52 |
53 | module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub'
54 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.png$' -> 'RelativeImageStub'
55 |
56 | suppress_type=$FlowIssue
57 | suppress_type=$FlowFixMe
58 | suppress_type=$FixMe
59 |
60 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-0]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
61 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-0]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
62 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
63 |
64 | [version]
65 | 0.20.1
66 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
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/IJ
26 | #
27 | .idea
28 | .gradle
29 | local.properties
30 |
31 | # node.js
32 | #
33 | node_modules/
34 | npm-debug.log
35 |
36 | # react native
37 | index.android.js
38 | index.ios.js
39 | android/
40 | ios/
41 |
--------------------------------------------------------------------------------
/.tern-project:
--------------------------------------------------------------------------------
1 | {
2 | "ecmaVersion": 6,
3 | "libs": [],
4 | "loadEagerly": [
5 | "js/**/*.js",
6 | "index.android.js",
7 | "index.ios.js"
8 | ],
9 | "plugins": {
10 | "modules": {},
11 | "es_modules": {}
12 | }
13 | }
--------------------------------------------------------------------------------
/.watchmanconfig:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2016-2020, Lucas Reis
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./js/swipe-actions');
--------------------------------------------------------------------------------
/js/components/example.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | import React from 'react';
3 | import {
4 | View,
5 | Text,
6 | Alert,
7 | StyleSheet
8 | } from 'react-native';
9 |
10 | import SwipeActions from '../swipe-actions';
11 |
12 | const styles = StyleSheet.create({
13 | actionsText: {
14 | fontSize: 18,
15 | color: '#fff',
16 | textAlign: 'center'
17 | },
18 | actionsView: {
19 | backgroundColor: '#0077B2',
20 | width: 100,
21 | height: 100,
22 | flex: 1,
23 | justifyContent: 'center',
24 | alignItems: 'center',
25 | borderRadius: 50,
26 | margin: 30,
27 | // android
28 | elevation: 10,
29 | // ios
30 | shadowColor: '#000000',
31 | shadowOpacity: 0.8,
32 | shadowRadius: 2,
33 | shadowOffset: {
34 | height: 1,
35 | width: 0
36 | }
37 | },
38 | exampleText: {
39 | fontSize: 32,
40 | fontWeight: 'bold',
41 | color: '#fff'
42 | },
43 | exampleView: {
44 | flex: 1,
45 | justifyContent: 'center',
46 | alignItems: 'center',
47 | backgroundColor: '#FF8D00'
48 | }
49 | });
50 |
51 | const action = pos => () =>
52 | Alert.alert(`${pos} Action Fired!`);
53 |
54 | const node = pos => (
55 |
56 |
57 | {`${pos} Action`}
58 |
59 | );
60 |
61 | export default React.createClass({
62 | displayName: 'RootComponent',
63 | render() {
64 | return (
65 |
70 |
71 |
72 | Child Component
73 |
74 |
75 | );
76 | }
77 | });
78 |
--------------------------------------------------------------------------------
/js/swipe-actions.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | import React, { Component } from 'react'
3 | import {
4 | StyleSheet,
5 | View,
6 | Animated,
7 | PanResponder,
8 | Dimensions
9 | } from 'react-native';
10 | import PropTypes from 'prop-types';
11 |
12 | import { between } from './util';
13 |
14 | const Window = Dimensions.get('window');
15 |
16 | const MAX_Y = Window.height / 6;
17 |
18 | const styles = StyleSheet.create({
19 | container: {
20 | flex: 1
21 | },
22 | actionContainer: {
23 | position: 'absolute',
24 | width: Window.width,
25 | left: 0,
26 | top: 0,
27 | backgroundColor: 'transparent'
28 | },
29 | actionContents: {
30 | alignItems: 'center'
31 | }
32 | });
33 |
34 | export default class SwipeActions extends Component {
35 | constructor(props) {
36 | super(props);
37 | this.state = {
38 | anim: new Animated.Value(0),
39 | };
40 | }
41 |
42 | propTypes: {
43 | children: PropTypes.node.isRequired,
44 | upperAction: PropTypes.func,
45 | lowerAction: PropTypes.func,
46 | upperNode: PropTypes.node,
47 | lowerNode: PropTypes.node
48 | };
49 | componentWillMount() {
50 | const upperAction = this.props.upperAction
51 | ? this.props.upperAction
52 | : () => {};
53 |
54 | const lowerAction = this.props.lowerAction
55 | ? this.props.lowerAction
56 | : () => {};
57 |
58 | this.panResponder = PanResponder.create({
59 | onStartShouldSetPanResponder: () => true,
60 | onPanResponderMove: (e, gesture) => {
61 | const dy = between(gesture.dy, -MAX_Y, MAX_Y);
62 | this.state.anim.setValue(dy);
63 | },
64 | onPanResponderRelease: (e, gesture) => {
65 | const dy = between(gesture.dy, -MAX_Y, MAX_Y);
66 |
67 | if (dy === MAX_Y) {
68 | upperAction();
69 | } else if (dy === -MAX_Y) {
70 | lowerAction();
71 | }
72 |
73 | Animated.timing(
74 | this.state.anim,
75 | { toValue: 0 }
76 | ).start();
77 | }
78 | });
79 | };
80 | renderAction({ node, topInterpolation, opacityInterpolation }) {
81 | if (node) {
82 | const s = [styles.actionContainer, {
83 | top: this.state.anim.interpolate(topInterpolation),
84 | opacity: this.state.anim.interpolate(opacityInterpolation)
85 | }];
86 |
87 | return (
88 |
89 | {node}
90 |
91 | );
92 | }
93 | return null;
94 | };
95 | renderUpperAction() {
96 | return this.renderAction({
97 | node: this.props.upperNode,
98 | topInterpolation: {
99 | inputRange: [-MAX_Y, 0, MAX_Y],
100 | outputRange: [-2 * MAX_Y, -2 * MAX_Y, 0]
101 | },
102 | opacityInterpolation: {
103 | inputRange: [-MAX_Y, 0, 0.8 * MAX_Y, MAX_Y],
104 | outputRange: [0, 0, 0.5, 1]
105 | }
106 | });
107 | };
108 | renderLowerAction() {
109 | return this.renderAction({
110 | node: this.props.lowerNode,
111 | topInterpolation: {
112 | inputRange: [-MAX_Y, 0, MAX_Y],
113 | outputRange: [Window.height - 2 * MAX_Y, Window.height, Window.height + MAX_Y] // + (MAX_Y / 2)
114 | },
115 | opacityInterpolation: {
116 | inputRange: [-MAX_Y, 0.8 * -MAX_Y, 0, MAX_Y],
117 | outputRange: [1, 0.5, 0, 0]
118 | }
119 | });
120 | };
121 | render() {
122 | return (
123 |
124 | {this.props.children}
125 | {this.renderUpperAction()}
126 | {this.renderLowerAction()}
127 |
128 | );
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/js/util.js:
--------------------------------------------------------------------------------
1 | //
2 | // Simple, pure functions
3 | //
4 |
5 | export const between = (x, min, max) =>
6 | x < min
7 | ? min
8 | : x > max
9 | ? max
10 | : x;
11 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "swipe-actions",
3 | "author": "Lucas Reis",
4 | "keywords": [
5 | "react",
6 | "react-native",
7 | "react-component",
8 | "ios",
9 | "android",
10 | "actions",
11 | "action",
12 | "swipe",
13 | "gestures",
14 | "gesture"
15 | ],
16 | "version": "1.1.0",
17 | "main": "index.js",
18 | "description": "React Native component for firing actions based on swipe gestures",
19 | "peerDependencies": {
20 | "react-native": ">=0.14.0"
21 | },
22 | "repository": {
23 | "type": "git",
24 | "url": "git+https://github.com/lucasmreis/swipe-actions.git"
25 | },
26 | "bugs": {
27 | "url": "https://github.com/lucasmreis/swipe-actions/issues"
28 | },
29 | "homepage": "https://github.com/lucasmreis/swipe-actions#readme",
30 | "license": "MIT",
31 | "marlint": {
32 | "rules": {
33 | "operator-linebreak": [2, "before"]
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # SwipeActions
2 |
3 | React Native component for firing actions based on swipe gestures:
4 |
5 | 
6 |
7 | ## Install
8 |
9 | ```js
10 | npm install swipe-actions --save
11 | ```
12 |
13 | ## Use
14 |
15 | Wrap main component in ``, pass two components and two callbacks as the upper and lower actions:
16 |
17 | ```js
18 | const mainComponent = (
19 |
20 | Child Component
21 |
22 | );
23 |
24 | // components shown on swipe
25 | const node = pos => (
26 |
27 |
28 | {`${pos} Action`}
29 |
30 | );
31 |
32 | // callbacks fired on release
33 | const action = pos => () =>
34 | Alert.alert(`${pos} Action Fired!`);
35 |
36 |
41 | {mainComponent}
42 |
43 | ```
44 |
45 | Please [★ on GitHub](https://github.com/lucasmreis/swipe-actions)!
46 |
--------------------------------------------------------------------------------
/swipe-actions.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lucasmreis/swipe-actions/a6bb2e8fdbe3b86de0d4f0823d253e79e57ebc87/swipe-actions.gif
--------------------------------------------------------------------------------