Skip to content
This repository was archived by the owner on Jan 25, 2023. It is now read-only.

Commit e80c44f

Browse files
committed
wip
t
1 parent bb9e945 commit e80c44f

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Animated } from 'react-native';
2+
import React from 'react';
3+
import get from 'lodash/get';
4+
5+
export default ARComponent => {
6+
// there is a strange issue: animatedvalues can't be child objects,
7+
// so we have to flatten them
8+
// we would need to have an Animated.ValueXYZ
9+
const ANIMATEABLE3D = ['position', 'eulerAngles'];
10+
const ARComponentAnimatedInner = Animated.createAnimatedComponent(
11+
class extends React.Component {
12+
render() {
13+
// unflatten
14+
const unflattened = {};
15+
ANIMATEABLE3D.forEach(key => {
16+
unflattened[key] = {
17+
x: get(this.props, `${key}_x`),
18+
y: get(this.props, `${key}_y`),
19+
z: get(this.props, `${key}_z`),
20+
};
21+
});
22+
return <ARComponent {...this.props} {...unflattened} />;
23+
}
24+
},
25+
);
26+
27+
return props => {
28+
const flattenedProps = {};
29+
30+
ANIMATEABLE3D.forEach(key => {
31+
flattenedProps[`${key}_x`] = get(props, [key, 'x']);
32+
flattenedProps[`${key}_y`] = get(props, [key, 'y']);
33+
flattenedProps[`${key}_z`] = get(props, [key, 'z']);
34+
});
35+
return <ARComponentAnimatedInner {...props} {...flattenedProps} />;
36+
};
37+
};

components/lib/createArComponent.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import {
2020
scale,
2121
transition,
2222
} from './propTypes';
23-
import processMaterial from './processMaterial';
23+
import addAnimatedSupport from './addAnimatedSupport';
2424
import generateId from './generateId';
25+
import processMaterial from './processMaterial';
2526

2627
const { ARGeosManager } = NativeModules;
2728

@@ -227,8 +228,8 @@ export default (mountConfig, propTypes = {}, nonUpdateablePropKeys = []) => {
227228
return null;
228229
}
229230
};
231+
const ARComponentAnimated = addAnimatedSupport(ARComponent);
232+
ARComponentAnimated.propTypes = allPropTypes;
230233

231-
ARComponent.propTypes = allPropTypes;
232-
233-
return ARComponent;
234+
return ARComponentAnimated;
234235
};

components/lib/propTypes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import PropTypes from 'prop-types';
55
const ARKitManager = NativeModules.ARKitManager;
66

77
export const position = PropTypes.shape({
8-
x: PropTypes.number,
9-
y: PropTypes.number,
10-
z: PropTypes.number,
8+
x: PropTypes.oneOfType([PropTypes.number, PropTypes.object]),
9+
y: PropTypes.oneOfType([PropTypes.number, PropTypes.object]),
10+
z: PropTypes.oneOfType([PropTypes.number, PropTypes.object]),
1111
});
1212

1313
export const scale = PropTypes.number;

0 commit comments

Comments
 (0)