Skip to content

Commit

Permalink
bump
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanBacon committed Jan 31, 2019
1 parent 598e3c9 commit ecd4e5c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
49 changes: 35 additions & 14 deletions lib/ARCameraState.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,40 @@ const removeSuffix = str => {
}
};

const { TrackingState = {}, TrackingStateReason = {}, EventType = {} } = AR;
const {
TrackingState,
TrackingStates = {},
TrackingStateReason,
TrackingStateReasons = {},
EventType,
EventTypes = {},
} = AR;

const ARReasons = TrackingStateReason || TrackingStateReasons;
const ARState = TrackingState || TrackingStates;
const AREventType = EventType || EventTypes;
class ARCameraState extends React.Component {
state = {};
static defaultProps = {
[TrackingStateReason.None]: { title: 'Having trouble collecting data' },
[TrackingStateReason.Initializing]: {
[ARReasons.None]: { title: 'Having trouble collecting data' },
[ARReasons.Initializing]: {
title: 'Initializing',
subtitle: 'Move the camera around for better results',
},
[TrackingStateReason.ExcessiveMotion]: {
[ARReasons.ExcessiveMotion]: {
title: 'Excessive motion',
subtitle: 'Try moving your camera slower',
},
[TrackingStateReason.InsufficientFeatures]: {
[ARReasons.InsufficientFeatures]: {
title: 'insufficient features',
subtitle: 'Try moving your camera around more',
},
[TrackingStateReason.Relocalizing]: { title: 'Relocalizing' },
[ARReasons.Relocalizing]: { title: 'Relocalizing' },

trackingStateStyles: {
[TrackingState.NotAvailable]: { color: '#D0021B' },
[TrackingState.Limited]: { color: '#F5C423' },
[TrackingState.Normal]: { color: '#ffffff' },
[ARState.NotAvailable]: { color: '#D0021B' },
[ARState.Limited]: { color: '#F5C423' },
[ARState.Normal]: { color: '#ffffff' },
},
};
componentDidMount() {
Expand All @@ -45,31 +55,42 @@ class ARCameraState extends React.Component {

componentWillUnmount() {
if (AR.isAvailable() && AR.removeAllListeners) {
AR.removeAllListeners(EventType.CameraDidChangeTrackingState);
AR.removeAllListeners(AREventType.CameraDidChangeTrackingState);
}
}

render() {
const { style, titleStyle, subtitleStyle, children, trackingStateStyles } = this.props;
const {
style,
isVisible,
titleStyle,
subtitleStyle,
children,
trackingStateStyles,
} = this.props;
const { trackingState, trackingStateReason } = this.state;

let trackingStateMessage = {};
const _trackingState = removeSuffix(trackingState);
let trackingStateStyle = trackingStateStyles[_trackingState] || {};

switch (_trackingState) {
case TrackingState.NotAvailable:
case ARState.NotAvailable:
trackingStateMessage = { title: 'Not Available' };
break;
case TrackingState.Limited:
case ARState.Limited:
const reason = removeSuffix(trackingStateReason);
trackingStateMessage = this.props[reason];
break;
case TrackingState.Normal:
case ARState.Normal:
break;
}
const { title, subtitle } = trackingStateMessage;

if (!isVisible) {
return null;
}

return (
<View style={[styles.container, style]}>
{title && <Text style={[styles.title, trackingStateStyle, titleStyle]}>{title}</Text>}
Expand Down
13 changes: 10 additions & 3 deletions lib/GraphicsView.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default class GraphicsView extends React.Component<Props> {
onContextCreate={this._onContextCreate}
/>
{isArEnabled && isArRunningStateEnabled && <ARRunningState {...runningProps} />}
{isArEnabled && isArCameraStateEnabled && <ARCameraState {...cameraProps} />}
{isArEnabled && <ARCameraState isVisible={isArCameraStateEnabled} {...cameraProps} />}
</View>
);
}
Expand Down Expand Up @@ -164,8 +164,15 @@ export default class GraphicsView extends React.Component<Props> {
}

if (isArEnabled === true) {
const { TrackingConfiguration = {} } = AR;
const trackingConfiguration = arTrackingConfiguration || TrackingConfiguration.World;
const { TrackingConfiguration, TrackingConfigurations } = AR;
const finalConfig = TrackingConfiguration || TrackingConfigurations;
if (!arTrackingConfiguration) {
invariant(
finalConfig,
'AR Cannot be run because TrackingConfiguration(s) are not defined.'
);
}
const trackingConfiguration = arTrackingConfiguration || finalConfig.World;
// Start AR session
await AR.startAsync(findNodeHandle(this.nativeRef), trackingConfiguration);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "expo-graphics",
"version": "1.0.2",
"version": "1.0.3",
"description": "Tools for building graphic based components in Expo",
"author": "Evan Bacon <[email protected]> (https://expo.io/)",
"files": [
Expand Down

0 comments on commit ecd4e5c

Please sign in to comment.