Skip to content

Commit

Permalink
fix: partially fix #185
Browse files Browse the repository at this point in the history
  • Loading branch information
nandorojo committed Mar 31, 2022
1 parent afa1114 commit a4d7d18
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 17 deletions.
3 changes: 2 additions & 1 deletion examples/with-expo/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// export { default } from './src/Moti.Loop'
// export { default } from './src/Moti.Skeleton'
// export { default } from './src/Moti.Gallery'
export { default } from './src/Moti.Sequence'
// export { default } from './src/Moti.Sequence'
export { default } from './src/Moti.Factory'
// export { default } from './src/Moti.KeyPresence'
// export { default } from './src/Moti.Transform'
// export { default } from './src/Moti.Pressable'
Expand Down
47 changes: 47 additions & 0 deletions examples/with-expo/src/Moti.Factory.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react'
import { MotiPressable } from 'moti/interactions'
import { useSharedValue } from 'react-native-reanimated'
import { MotiView } from 'moti'

// @ts-expect-error internal
global.shouldDebugMoti = false

export default function Factory() {
const on = useSharedValue(true)
return (
<MotiPressable
containerStyle={{ flex: 1, backgroundColor: 'blue' }}
style={{ height: '100%', justifyContent: 'center', alignItems: 'center' }}
animate={(interaction) => {
'worklet'

// console.log('[animate] pressable', interaction)

return {
// opacity: on.value ? 1 : 0,
}
}}
>
{(interaction) => (
<MotiView
animate={() => {
'worklet'
const { pressed } = interaction.value

console.log('[moti-pressable]', interaction.value)

return {
scale: pressed ? 0.7 : 1,
}
}}
style={{
height: 300,
width: 300,
borderRadius: 16,
backgroundColor: 'white',
}}
/>
)}
</MotiPressable>
)
}
11 changes: 2 additions & 9 deletions examples/with-expo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@motify/*": [
"../../packages/*/src"
],
"moti": [
"../../packages/moti/src"
]
"moti": ["../../packages/moti/src"]
},
"jsx": "react-native",
"target": "esnext",
"lib": [
"esnext"
],
"lib": ["esnext"],
"allowJs": true,
"skipLibCheck": true,
"noEmit": true,
Expand Down
1 change: 0 additions & 1 deletion examples/with-next/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"lib": ["dom", "dom.iterable", "esnext"],
"baseUrl": ".",
"paths": {
"@motify/*": ["../../packages/*/src"],
"moti": ["../../packages/moti/src"]
},
"allowJs": true,
Expand Down
19 changes: 13 additions & 6 deletions packages/core/src/use-map-animate-to-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ import type {

const debug = (...args: any[]) => {
'worklet'

// @ts-expect-error moti
if (!global.shouldDebugMoti) {
return
}

if (args) {
// hi
}
// console.log('[moti]', ...args)
console.log('[moti]', ...args)
}

const isColor = (styleKey: string) => {
Expand Down Expand Up @@ -136,7 +142,7 @@ function animationConfig<Animate>(
repeatReverse = transition.repeatReverse
}

debug({ loop, key, repeatCount, animationType })
// debug({ loop, key, repeatCount, animationType })

let config = {}
// so sad, but fix it later :(
Expand Down Expand Up @@ -264,15 +270,16 @@ export function useMotify<Animate>({

let animateStyle: Animate

if (animateProp && 'value' in animateProp) {
if (typeof animateProp == 'function') {
animateStyle = (animateProp() || {}) as Animate
} else if (animateProp && 'value' in animateProp) {
animateStyle = (animateProp.value || {}) as Animate
} else {
if (typeof animateProp == 'function') {
animateStyle = animateProp() as Animate
}
animateStyle = (animateProp || {}) as Animate
}

debug('style', animateStyle)

const initialStyle = fromProp || {}
let exitStyle = exitProp || {}
if (typeof exitStyle === 'function') {
Expand Down

0 comments on commit a4d7d18

Please sign in to comment.