This repository has been archived by the owner on Jan 25, 2023. It is now read-only.
forked from react-native-ar/react-native-arkit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request react-native-ar#150 from HippoAR/improve-animations
support React-native Animated Library
- Loading branch information
Showing
3 changed files
with
64 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Animated } from 'react-native'; | ||
import React from 'react'; | ||
import get from 'lodash/get'; | ||
|
||
export default ARComponent => { | ||
// there is a strange issue: animatedvalues can't be child objects, | ||
// so we have to flatten them | ||
// we would need to have an Animated.ValueXYZ | ||
const ANIMATEABLE3D = ['position', 'eulerAngles']; | ||
|
||
const ARComponentAnimatedInner = Animated.createAnimatedComponent( | ||
class extends React.Component { | ||
render() { | ||
// unflatten | ||
const unflattened = {}; | ||
|
||
ANIMATEABLE3D.forEach(key => { | ||
unflattened[key] = { | ||
x: get(this.props, `${key}_x`), | ||
y: get(this.props, `${key}_y`), | ||
z: get(this.props, `${key}_z`), | ||
}; | ||
}); | ||
return <ARComponent {...this.props} {...unflattened} />; | ||
} | ||
}, | ||
); | ||
|
||
return props => { | ||
const flattenedProps = {}; | ||
|
||
ANIMATEABLE3D.forEach(key => { | ||
flattenedProps[`${key}_x`] = get(props, [key, 'x']); | ||
flattenedProps[`${key}_y`] = get(props, [key, 'y']); | ||
flattenedProps[`${key}_z`] = get(props, [key, 'z']); | ||
}); | ||
return <ARComponentAnimatedInner {...props} {...flattenedProps} />; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters