Skip to content

Commit

Permalink
add runNow for AR.resume
Browse files Browse the repository at this point in the history
  • Loading branch information
hokaiyipFS authored Apr 5, 2019
1 parent ecd4e5c commit 65dd56f
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions lib/ARRunningState.ios.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// @flow
import { Ionicons } from '@expo/vector-icons';
import { AR } from 'expo';
import {Ionicons} from '@expo/vector-icons';
import {AR} from 'expo';
import React from 'react';
import { TouchableOpacity, View } from 'react-native';
import {TouchableOpacity, View} from 'react-native';

// import AR from '../__tests__/AR.mock';

class IconButton extends React.PureComponent {
render() {
const { style, onPress, icon } = this.props;
const {style, onPress, icon} = this.props;
return (
<TouchableOpacity style={style} onPress={onPress}>
<View
Expand All @@ -19,21 +19,29 @@ class IconButton extends React.PureComponent {
justifyContent: 'center',
alignItems: 'center',
}}>
<Ionicons name={icon} size={32} color="white" />
<Ionicons name={icon} size={32} color="white"/>
</View>
</TouchableOpacity>
);
}
}

class ARRunningState extends React.Component {
state = { running: true };
state = {running: true};

componentDidMount() {
if (AR.isAvailable()) {
this._onSessionWasInterrupted = AR.onSessionWasInterrupted(() => {
this.pause();
});


if (this.state.running) {
setTimeout(function () {
this.runNow();
}.bind(this), 1000);

}
}
}

Expand All @@ -56,7 +64,7 @@ class ARRunningState extends React.Component {
},
this.props.style,
]}>
<IconButton icon={this.iconName} onPress={this.onPress} />
<IconButton icon={this.iconName} onPress={this.onPress}/>
</View>
);
}
Expand All @@ -74,10 +82,10 @@ class ARRunningState extends React.Component {
};

toggleRunning = () => {
this.setState({ running: !this.state.running }, () => {
this.setState({running: !this.state.running}, () => {
if (!AR.isAvailable()) return;

const { running } = this.state;
const {running} = this.state;
if (running) {
AR.resume();
} else {
Expand All @@ -86,8 +94,17 @@ class ARRunningState extends React.Component {
});
};

runNow = () => {
this.setState({running: true}, () => {
if (!AR.isAvailable()) return;
AR.resume();

});
};

get iconName() {
return this.state.running ? 'md-play' : 'md-pause';
}
}

export default ARRunningState;

0 comments on commit 65dd56f

Please sign in to comment.