Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Migrate to reanimated 2 #68

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = function (api) {
},
},
],
['react-native-reanimated/plugin'],
],
}
}
1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
"react-native-reanimated": "~2.3.1",
"react-native-unimodules": "~0.15.0",
"react-native-web": "0.17.1"
},
Expand Down
113 changes: 59 additions & 54 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { ModalOptions, ModalProvider, ModalStackConfig, createModalStack } from 'react-native-modalfy'
import { ImageBackground, Dimensions, StyleSheet, StatusBar, Easing, Text, Animated, Platform } from 'react-native'

import { ImageBackground, Dimensions, StyleSheet, StatusBar, Text, Platform } from 'react-native'
import Animated, { interpolate, runOnJS, withSpring, Easing } from 'react-native-reanimated'
import DemoModal from './components/DemoModal'
import IntroModal from './components/IntroModal'
import IntroButton from './components/IntroButton'
Expand Down Expand Up @@ -39,71 +39,76 @@ const config: ModalStackConfig = {
easing: Easing.inOut(Easing.exp),
duration: 500,
},
transitionOptions: (animatedValue) => ({
transform: [
{
translateY: animatedValue.interpolate({
inputRange: [0, 1, 2],
outputRange: [height, 0, height],
}),
},
],
}),
transitionOptions: (animatedValue) => {
'worklet'
return {
transform: [
{
translateY: interpolate(animatedValue.value, [0, 1, 2], [height, 0, height]),
},
],
}
},
},
// IntroModal: IntroModal,
ModalA: DemoModal,
ModalB: DemoModal,
ModalC: DemoModal,
}

const animate = (animatedValue: Animated.Value, toValue: number, callback?: () => void) => {
Animated.spring(animatedValue, {
const animate = (animatedValue: Animated.SharedValue<number>, toValue: number, callback?: () => void) => {
animatedValue.value = withSpring(
toValue,
damping: 10,
mass: 0.35,
stiffness: 100,
overshootClamping: true,
restSpeedThreshold: 0.001,
restDisplacementThreshold: 0.001,
useNativeDriver: true,
}).start(({ finished }) => {
if (finished) callback?.()
})
{
damping: 10,
mass: 0.35,
stiffness: 100,
overshootClamping: true,
restSpeedThreshold: 0.001,
restDisplacementThreshold: 0.001,
},
(finished) => {
if (finished) {
if (typeof callback === 'function') {
runOnJS(callback)()
}
}
},
)
// Animated.spring(animatedValue, {
// toValue,

// useNativeDriver: true,
// }).start(({ finished }) => {
// if (finished) callback?.()
// })
}

const defaultOptions: ModalOptions = {
backdropOpacity: 0.4,
animationIn: animate,
animationOut: animate,
transitionOptions: (animatedValue) => ({
opacity: animatedValue.interpolate({
inputRange: [0, 1, 2],
outputRange: [0, 1, 0.9],
}),
transform: [
{ perspective: 2000 },
{
translateX: animatedValue.interpolate({
inputRange: [0, 1, 2],
outputRange: [-width / 1.5, 0, width / 1.5],
extrapolate: 'clamp',
}),
},
{
rotateY: animatedValue.interpolate({
inputRange: [0, 1, 2],
outputRange: ['90deg', '0deg', '-90deg'],
extrapolate: 'clamp',
}),
},
{
scale: animatedValue.interpolate({
inputRange: [0, 1, 2],
outputRange: [1.2, 1, 0.9],
extrapolate: 'clamp',
}),
},
],
}),
transitionOptions: (animatedValue) => {
'worklet'
return {
opacity: interpolate(animatedValue.value, [0, 1, 2], [0, 1, 0.9]),
transform: [
{ perspective: 2000 },
{
translateX: interpolate(animatedValue.value, [0, 1, 2], [-width / 1.5, 0, 10]),
},
// {
// rotateY: interpolate(animatedValue.value, [0, 1, 2], [90, 0, -90]) + 'deg',
// },
{
rotate: interpolate(animatedValue.value, [0, 1, 2], [45, 0, 45]) + 'deg',
},
// {
// scale: interpolate(animatedValue.value, [0, 1, 2], [1.2, 1, 0.9]),
// },
],
}
},
}

const stack = createModalStack<ModalStackParamsList>(config, defaultOptions)
Expand Down
48 changes: 47 additions & 1 deletion example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@
dependencies:
"@babel/helper-plugin-utils" "^7.16.7"

"@babel/plugin-transform-object-assign@^7.0.0":
"@babel/plugin-transform-object-assign@^7.0.0", "@babel/plugin-transform-object-assign@^7.10.4":
version "7.16.7"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-object-assign/-/plugin-transform-object-assign-7.16.7.tgz#5fe08d63dccfeb6a33aa2638faf98e5c584100f8"
integrity sha512-R8mawvm3x0COTJtveuoqZIjNypn2FjfvXZr4pSQ8VhEFBuQGBz4XhHasZtHXjgXU4XptZ4HtGof3NoYc93ZH9Q==
Expand Down Expand Up @@ -1962,6 +1962,11 @@
resolved "https://registry.yarnpkg.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz#0ea7b61496902b95890dc4c3a116b60cb8dae812"
integrity sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ==

"@types/invariant@^2.2.35":
version "2.2.35"
resolved "https://registry.yarnpkg.com/@types/invariant/-/invariant-2.2.35.tgz#cd3ebf581a6557452735688d8daba6cf0bd5a3be"
integrity sha512-DxX1V9P8zdJPYQat1gHyY0xj3efl8gnMVjiM9iCY6y27lj+PoQWkgjt8jDqmovPqULkKVpKRg8J36iQiA+EtEg==

"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz#8467d4b3c087805d63580480890791277ce35c44"
Expand Down Expand Up @@ -7848,6 +7853,11 @@ mkdirp@^1.0.3, mkdirp@^1.0.4:
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==

mockdate@^3.0.2:
version "3.0.5"
resolved "https://registry.yarnpkg.com/mockdate/-/mockdate-3.0.5.tgz#789be686deb3149e7df2b663d2bc4392bc3284fb"
integrity sha512-iniQP4rj1FhBdBYS/+eQv7j1tadJ9lJtdzgOpvsOHng/GbcDh2Fhdeq+ZRldrPYdXvCyfFUmFeEwEGXZB5I/AQ==

move-concurrently@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"
Expand Down Expand Up @@ -9399,6 +9409,11 @@ react-error-overlay@^6.0.9:
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.10.tgz#0fe26db4fa85d9dbb8624729580e90e7159a59a6"
integrity sha512-mKR90fX7Pm5seCOfz8q9F+66VCc1PGsWSBxKbITjfKVQHMNF2zudxHnMdJiB1fRCb+XsbQV9sO9DCkgsMQgBIA==

react-freeze@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/react-freeze/-/react-freeze-1.0.0.tgz#b21c65fe1783743007c8c9a2952b1c8879a77354"
integrity sha512-yQaiOqDmoKqks56LN9MTgY06O0qQHgV4FUrikH357DydArSZHQhl0BJFqGKIZoTqi8JizF9Dxhuk1FIZD6qCaw==

react-is@^16.13.1, react-is@^16.7.0:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
Expand Down Expand Up @@ -9429,6 +9444,27 @@ react-native-gesture-handler@~2.1.0:
lodash "^4.17.21"
prop-types "^15.7.2"

react-native-reanimated@~2.3.1:
version "2.3.3"
resolved "https://registry.yarnpkg.com/react-native-reanimated/-/react-native-reanimated-2.3.3.tgz#73de8ea495e59a091d848741e7037ac55d0235c4"
integrity sha512-uQofwsWUoKLY4QDgSdNbRxnqQDaQEPLLBNO9SP64JfQ2fDRJD5rjb4d3S29F0z9FqTnsWEwTL2Sl0spdx9xvHA==
dependencies:
"@babel/plugin-transform-object-assign" "^7.10.4"
"@types/invariant" "^2.2.35"
invariant "^2.2.4"
lodash.isequal "^4.5.0"
mockdate "^3.0.2"
react-native-screens "^3.4.0"
string-hash-64 "^1.0.3"

react-native-screens@^3.4.0:
version "3.13.1"
resolved "https://registry.yarnpkg.com/react-native-screens/-/react-native-screens-3.13.1.tgz#b3b1c5788dca25a71668909f66d87fb35c5c5241"
integrity sha512-xcrnuUs0qUrGpc2gOTDY4VgHHADQwp80mwR1prU/Q0JqbZN5W3koLhuOsT6FkSRKjR5t40l+4LcjhHdpqRB2HA==
dependencies:
react-freeze "^1.0.0"
warn-once "^0.1.0"

react-native-unimodules@~0.15.0:
version "0.15.0"
resolved "https://registry.yarnpkg.com/react-native-unimodules/-/react-native-unimodules-0.15.0.tgz#8d4fdb14f18490d13a4c422c9f49aa090204d878"
Expand Down Expand Up @@ -10516,6 +10552,11 @@ stream-shift@^1.0.0:
resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.1.tgz#d7088281559ab2778424279b0877da3c392d5a3d"
integrity sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ==

string-hash-64@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/string-hash-64/-/string-hash-64-1.0.3.tgz#0deb56df58678640db5c479ccbbb597aaa0de322"
integrity sha512-D5OKWKvDhyVWWn2x5Y9b+37NUllks34q1dCDhk/vYcso9fmhs+Tl3KR/gE4v5UNj2UA35cnX4KdVVGkG1deKqw==

string-width@^3.0.0, string-width@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961"
Expand Down Expand Up @@ -11389,6 +11430,11 @@ walker@^1.0.7, walker@~1.0.5:
dependencies:
makeerror "1.0.12"

warn-once@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/warn-once/-/warn-once-0.1.0.tgz#4f58d89b84f968d0389176aa99e0cf0f14ffd4c8"
integrity sha512-recZTSvuaH/On5ZU5ywq66y99lImWqzP93+AiUo9LUwG8gXHW+LJjhOd6REJHm7qb0niYqrEQJvbHSQfuJtTqA==

watchpack-chokidar2@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/watchpack-chokidar2/-/watchpack-chokidar2-2.0.1.tgz#38500072ee6ece66f3769936950ea1771be1c957"
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@
"react-native": "0.66.4",
"react-native-builder-bob": "^0.18.2",
"react-native-gesture-handler": "^1.10.3",
"react-native-reanimated": "^2.4.1",
"release-it": "^14.2.2",
"typescript": "^4.5.4"
},
"peerDependencies": {
"react": ">=16.8.3",
"react-native": ">=0.59.0",
"react-native-gesture-handler": ">=1.9.0"
"react-native-gesture-handler": ">=1.9.0",
"react-native-reanimated": ">=2.3.1"
},
"husky": {
"hooks": {
Expand Down
Loading