• Stars
    star
    5,171
  • Rank 7,635 (Top 0.2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Experimental implementation of high performance interactable views in React Native

              

Interactable

react-native-interactable


NPM Version Build Status NPM Downloads

LOOKING FOR A MAINTAINER

We love this project, but currently we don’t have enough time to work on it. So we are looking for a maintainer. If you have enough time and knowledge and want to become one - please let us know ([email protected])


Description


This is an experimental implementation of a declarative API for handling fluid user interactions with views at 60 FPS in React Native. Here are some example use-cases for views that users can interact with:
  • Swipeable card (a la Google Now) springing into place unless swiped away with enough force
  • Drawer snapping between closed and open with buttons appearing gradually as it's being dragged
  • Collapsible header that snaps to a smaller size as the content below is being scrolled
  • Chat heads (a la Facebook Messenger) that can be dragged around but snap to corners of the screen

All of these use-cases have views that continuously interact with the user's gestures. These interactions are normally physical in nature, having properties like springiness, friction, elasticity and damping. In order to feel natural on a touch device they need to run at 60 FPS.

Why is this challenging?

The async nature of the React Native bridge incurs an inherent performance penalty. This traditionally prevents JavaScript code from running at high framerates. One of the most noticeable challenges is animations in JavaScript, which aren't guaranteed to run at 60 FPS.

Modern animation libraries for React Native, like Animated, tackle this challenge with a declarative approach. In order to minimize passes over the bridge, animations are only declared in JavaScript but executed by a native driver on the other side - in 60 FPS.

Fluid user interactions take this a step further than animations. Interactions require UI to continuously react to the user's gestures. This library is designed to support complex physical interactions with ease, using a full-fledged physics engine to drive the interaction on the native side.

Why is it named interactable?

First off, we are aware that interactable isn't a real word. The correct form is interactive but this has connotation that isn't necessarily related to physical interactions. Similar to Animated.View, we wanted to have Interactable.View - meaning a view you can interact with. And hey, Unity did it too.


Installation

Requires RN 0.40 and above.

  • Install the package from npm
npm install react-native-interactable --save
  • Link the native library to your project
react-native link react-native-interactable

Note: instead of linking automatically you can also link manually according to these instructions

node_modules/react-native-interactable/ios/Interactable.xcodeproj

Manually link via Cocoa Pods (iOS)

  • Add the following to your Podfile and run pod update:
pod 'Interactable', :path => '../node_modules/react-native-interactable'

Example



The playground project has few use-cases implemented like: swipeable card, drawer, collapsible header and chat heads under the "Basic examples" section. It's simplistic but easy to learn from.

Under the "Real life example" you'll find more complex demonstrations. They're harder to learn from, but they're cool to watch. More info about the UX inspirations for the demo app.

  • Build and run the example project To see the library in action, clone the repo and run the playground from the root folder:
  npm start
  npm run ios



Note: It's recommended to experience it on a real device and not on a simulator. The simulator has poor performance so the framerate isn't like the real thing.

Usage

The core of this library is the Interactable.View component, used to wrap views you want to interact with:

import Interactable from 'react-native-interactable';

<Interactable.View
  horizontalOnly={true}
  snapPoints={[{x: 0}, {x: -200}]}
  onSnap={this.onDrawerSnap}>

  // the view that you wrap here will now support interactions

</Interactable.View>

Interactable.View Props

Click here for the full reference for all props

  • snapPoints - a list of points the view will snap to after being dragged by the user
snapPoints={[{x: 0}, {x: -200}]}
  • springPoints - connect the view's center to a group of constant springs
springPoints={[{x: 0, tension: 6000, damping: 0.5, influenceArea: {left: 0}}]}
  • gravityPoints - attract/repel the view's center with a group of constant gravity wells
gravityPoints={[{x: 0, y: 0, strength: 8000, falloff: 40, damping: 0.5}]}
  • frictionAreas - add friction to the view's movement with a group of friction regions
frictionAreas={[{damping: 0.5, influenceArea: {top: 0}}]}
  • alertAreas - send alert event when the view's center enters/leaves any region within the group
alertAreas={[{id: 'myArea', influenceArea: {top: 0}}]}
  • horizontalOnly - whether the view should be locked to horizontal movement only
horizontalOnly={true}
  • startOnFront - [ANDROID ONLY] whether the view should call bringToFront
startOnFront
  • verticalOnly - whether the view should be locked to vertical movement only
verticalOnly={true}
  • boundaries - limits to movement relative to the view's center (after initial layout)
boundaries={{left: -100, right: 100, bounce: 0.5}}
  • onSnap - a function called whenever the view finishes snapping to a snapPoints point (after dragging)
onSnap={this.onDrawerSnap}
  • onSnapStart - a function called whenever the view starts snapping to a snapPoints point (after dragging)
onSnapStart={this.onDrawerSnapStart}
  • onStop - a function called whenever the interaction stops (views freeze momentarily)
onStop={this.onStopInteraction}
  • onDrag - a function called whenever the user starts or stops dragging the view
onDrag={this.onDragEvent}
  • onAlert - a function called whenever the view's center enters/leaves an alert area
onAlert={this.onAlertEvent}
  • dragEnabled - whether the user can drag the view or not
dragEnabled={true}
  • dragWithSpring - specify to make dragging behavior of the view occur using a spring
dragWithSpring={{tension: 2000, damping: 0.5}}
  • dragToss - time in seconds the view is allowed to be tossed before snapping to a point
dragToss={0.1}
animatedValueX={this._deltaX}
animatedValueY={this._deltaY}
animatedNativeDriver={false}
  • initialPosition - used to initialize the view's position to a position different than it's original center
initialPosition={{x: -140, y: -280}}

Interactable.View Methods

setVelocity(params) - used to imperatively set the view's velocity in order to move it around
instance.setVelocity({x: 2000});

Takes a single argument, which is a params object containing:

  • x - The horizontal velocity. Optional.
  • y - The vertical velocity. Optional.
snapTo(params) - used to imperatively cause the view to snap to one of its snap points
instance.snapTo({index: 2});

Takes a single argument, which is a params object containing:

  • index - The index of the snap point in the snapPoints array. Optional.
changePosition(params) - used to imperatively set the view's position
instance.changePosition({x: 120, y: 40});

Takes a single argument, which is a params object containing:

  • x - The x coordinate.
  • y - The y coordinate.

bringToFront() - bring view to front (Android Only)
instance.bringToFront();

Animating other views according to Interactable.View position

This library is integrated with the Animated library in order to support performant animations of other views according to the movement of the Interactable.View.

Consider the following use-cases:

  • Buttons that appear using a fade & scale animation under a drawer as it's being dragged (example)
  • Image in a collapsible header that scales as it's snapped between states (example)

In these use-cases, we have views different from the one the user is interacting with, that animate according to the interactive view's position. Since Animated library uses Animated.Value to animate view properties, we support setting the value of an Animated.Value instance according to position of the interactable view. The Animated.Value will contain the delta between the Interactable.View original center and new center. This can be done separately on the X axis and Y axis.

After setting this up, use Animated to declaratively define interpolations of the Animated.Value to various animatable view properties like opacity, scale, rotation, translateX and translateY:

this._deltaY = new Animated.Value(0);

<Animated.View style={{
  transform: [{
    scale: this._deltaY.interpolate({
      inputRange: [-150, -150, 0, 0],
      outputRange: [0.3, 0.3, 1, 1]
    })
  }]
}}>
  ...
</Animated.View>

<Interactable.View
  verticalOnly={true}
  snapPoints={[{y: 0}, {y: -150}]}
  animatedValueY={this._deltaY}
>
  ...
</Interactable.View>

Implementation Details

Originally, the iOS implementation relied on UIKit Dynamics - a powerful native animation engine for physical interactions. A physics engine is required in order to make the interaction life-like. Consider the action of tossing a view connected via a spring to a snap point. A simple native spring animation will not be enough to take the initial velocity vector into account.

At some point, UIKit Dynamics was dropped in favor of a home-brewed physics implementation in order to provide more control over the behaviors. This also paved the way for the Android port since there's no parallel to UIKit Dynamics for Android. The home-brewed physics engine was straightforward to port from Objective-C to Java and is now part of this library.

Contributing

If you are interested in the project, have feedback or want to contribute don't hesitate to contact me. I'm particularly interested in ideas on how to expand the declarative API for more use-cases and suggestions on how to improve performance. PRs are always welcome.

License

MIT

More Repositories

1

react-templates

Light weight templates for react
JavaScript
2,813
star
2

vscode-glean

The extension provides refactoring tools for your React codebase
TypeScript
1,455
star
3

mjml-react

React component library to generate the HTML emails on the fly
JavaScript
980
star
4

react-native-zss-rich-text-editor

React Native rich text editor based on ZSSRichTextEditor
HTML
838
star
5

react-native-keyboard-input

Use your own custom input component instead of the system keyboard
Objective-C
797
star
6

wml

An alternative to symlinks that actually copies changed files from source to destination folders
JavaScript
769
star
7

angular-tree-control

Angular JS Tree
HTML
709
star
8

DetoxInstruments

Detox Instruments is a performance–analysis and testing framework, designed to help developers profile their mobile apps in order to better understand and optimize their app's behavior and performance.
Objective-C
621
star
9

react-native-controllers

Native IOS Navigation for React Native (navbar, tabs, drawer)
Objective-C
610
star
10

react-native-autogrow-textinput

Objective-C
540
star
11

accord

Accord: A sane validation library for Scala
Scala
534
star
12

react-native-crash-course

The React Native crash course by Wix is a self-learning course designed to help you learn everything you need to know before diving into writing production code in React Native.
JavaScript
525
star
13

react-native-keyboard-aware-scrollview

Created by artald
JavaScript
485
star
14

wix-embedded-mysql

embedded mysql based on https://github.com/flapdoodle-oss/de.flapdoodle.embed.process
Java
379
star
15

DetoxRecorder

Detox Recorder is a utility for recordings steps for a Detox test as you use your app in Simulator. After recording the test, add expectations that check if interface elements are in the expected state.
Objective-C
286
star
16

react-dataflow-example

Experimenting with different dataflow approaches for a real life React app
JavaScript
279
star
17

eslint-plugin-lodash

ESLint rules for lodash
JavaScript
272
star
18

pro-gallery

Blazing fast & beautiful galleries built for the web
JavaScript
265
star
19

quix

Quix Notebook Manager
TypeScript
265
star
20

petri

Wix experiment system (A/B test and feature toggle framework)
JavaScript
264
star
21

redux-saga-tester

Full redux environment testing helper for redux-saga
JavaScript
249
star
22

react-native-wordpress-editor

React Native Wrapper for WordPress Rich Text Editor
Objective-C
246
star
23

redux-testkit

Complete and opinionated testkit for testing Redux projects (reducers, selectors, actions, thunks)
JavaScript
227
star
24

remx

Opinionated mobx
JavaScript
221
star
25

exodus

Easily migrate your JVM code from Maven to Bazel
Scala
221
star
26

react-native-action-view

An easy to use component that allows displaying swipeable buttons with a variety of transitions.
Objective-C
187
star
27

tdd-katas

TDD katas
JavaScript
175
star
28

react-native-custom-segmented-control

Custom version of the IOS SegmentedControl component
Objective-C
168
star
29

repluggable

Pluggable micro frontends in React+Redux apps
TypeScript
166
star
30

lerna-script

Lerna addon for adding custom tasks
JavaScript
164
star
31

react-native-wix-engine

Java
164
star
32

angular-widget

Lazy load isolated micro-apps in Angular
JavaScript
163
star
33

angular-viewport-watch

Angular directive that disables watchers in scopes out of viewport
JavaScript
148
star
34

react-native-keyboard-tracking-view

Objective-C
134
star
35

kampos

Tiny and fast effects compositor on WebGL
JavaScript
129
star
36

react-native-swipe-view

Native container for a React Native view which supports swipe behavior (for swipe to delete and such)
Java
124
star
37

list-view-experiments

React Native ListView Experiments
Objective-C
123
star
38

rn-perf-experiments

Various performance experiments with React Native over a swipeable card pattern
JavaScript
119
star
39

rn-perf-experiments2

React Native performance experiments revisited
JavaScript
115
star
40

codio

A media format to record and playback the process of programming
Kotlin
105
star
41

rn-synchronous-render

Experiments with synchronous rendering in React Native
Objective-C
104
star
42

react-native-gifted-chat

JavaScript
99
star
43

as-typed

Ambient mapping from JSON schema to typescript
TypeScript
98
star
44

playable

No hassle, no fuss, just nice and easy video player
TypeScript
95
star
45

tspoon

(DEPRECATED) AST visitors for TypeScript
TypeScript
83
star
46

remote-dom

JavaScript
82
star
47

react-native-paged-contacts

Paged contacts for React Native
Java
80
star
48

react-native-newrelic

New Relic reporting for React Native
JavaScript
79
star
49

obsidian

Dependency injection library for React and React Native applications
TypeScript
74
star
50

react-module-container

Small library for building micro apps in React and Angular
JavaScript
68
star
51

react-native-repackager

Custom extensions for react-native packager
JavaScript
67
star
52

rapido

🏃 A site performance test kit, built using Chrome's DevTools.
JavaScript
63
star
53

BindingListView

React Native ListView experimental implementation supporting direct view binding
Objective-C
62
star
54

rawss

Generic CSS polyfill framework, with a CSS variables implementation
TypeScript
59
star
55

wix-animations

Tools for easy and simple animating capabilities
JavaScript
59
star
56

haste

An extendable, blazing fast build system that cares about user experience
JavaScript
58
star
57

kafka-connect-s3

A Kafka-Connect Sink for S3 with no Hadoop dependencies.
Java
56
star
58

unidriver

UniDriver - Universal Component Drivers 🚀
TypeScript
53
star
59

carmi

CARMI - Compiler for Automatic Reactive Modelling of Inference
JavaScript
49
star
60

mobile-crash-course

Crash course for engineers in Wix to start working on the mobile stack
49
star
61

react-native-extended-cli

Extended CLI with convenient scripts and utilities for developing React Native apps
Shell
47
star
62

protractor-helpers

Set of matchers, locators, and helper functions for Protractor
JavaScript
46
star
63

Kompot

Component testing for React Native using Detox
JavaScript
45
star
64

future-perfect

A helper for Futures covering non-functional concerns such as retries, timeouts and reporting
Scala
44
star
65

mjml-react-example

mjml-react example project
JavaScript
42
star
66

specs2-jmock

This is a specs2 adapter + DSL for using the popular mocking framework JMock
Scala
41
star
67

corvid

Download your Wix site, code in a local IDE, collaborate, use git, and more!
JavaScript
39
star
68

javascript-essentials

Essential reading and learning materials for Wix client-side engineers
37
star
69

fed-training-kit

A self-guided onboarding kit for new FED Guild members
JavaScript
35
star
70

commons-validator-js

JavaScript port of Apache Commons Validator
JavaScript
35
star
71

DeviantArt-API

The DeviantArt API
35
star
72

redux-cornell

A Redux library which helps reduce boilerplate
TypeScript
34
star
73

wix-http-testkit

Tools for testing HTTP services
Scala
34
star
74

DetoxSync

Synchronization framework for Detox and other testing frameworks
Objective-C
34
star
75

enzyme-drivers

Enzyme Drivers is a JavaScript library that makes react component testing with enzyme a lot easier and fun to write
JavaScript
33
star
76

mutable

State containers with dirty checking and more
JavaScript
32
star
77

eyes.it

Add screenshot comparison to existing protractor tests simply by changing `it` to `eyes.it`
JavaScript
31
star
78

react-native-sane-listview

Why do we need all this datasource nonsense?!
JavaScript
31
star
79

wix-ui-backoffice

Common React UI components for all Wix backoffice React applications
TypeScript
31
star
80

turnerjs

An angular test kit for components and directives. See:
TypeScript
29
star
81

zorechka-bot

Github bot for keeping your Bazel dependencies up-to-date and clean
Scala
27
star
82

Koboshi

Obsessed with your precious data
Scala
27
star
83

react-popup-manager

Manage react popups, Modals, Lightboxes, Notifications
TypeScript
26
star
84

sample-wix-rest-app

JavaScript
24
star
85

wix-react-native-storybook-template

Server to host storybook for react native apps
JavaScript
24
star
86

wix-code-docs

Wix Code Reference Documentation - docworks jsons
JavaScript
24
star
87

hello-react-templates

Starter project for react-templates
JavaScript
24
star
88

react-native-open-file

Objective-C
24
star
89

isolated-runtime

Run untrusted Javascript code in a multi-tenant, isolated environment
JavaScript
23
star
90

react-hoverbox

Created by malsomnus
JavaScript
23
star
91

react-sequence-animator

A React library for sequence animations
TypeScript
23
star
92

fast-boot

Caching of the FS location of node modules between node process startups
JavaScript
22
star
93

wixmadefor

Wix Madefor font
Python
22
star
94

svg2react-icon

Generate React icon components from SVG raw files
JavaScript
22
star
95

quick-2fa

Safely generate two-factor authentication tokens into clipboard
JavaScript
21
star
96

async-graph-resolver

A Utility to handle execution and aggregation of async actions
TypeScript
21
star
97

DetoxIPC

DetoxIPC is an asynchronous, bi-directional inter-process remote invocation library for Apple platforms with an API similar to Apple's NSXPCConnection.
Objective-C
21
star
98

react-native-animation-library

JavaScript
20
star
99

data-capsule

A pluggable capsule for storing key/value data for your application
TypeScript
20
star
100

DTXLoggingInfra

Logging infrastructure for Apple platforms
Objective-C
18
star