Skip to content

Commit

Permalink
fix(internal): don't unmount the whole camera screen on focus loss
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaclennan committed Apr 24, 2019
1 parent c765d43 commit 840ebab
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/frontend/lib/withNavigationFocus.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React from "react";
import { View } from "react-native";
import hoistStatics from "hoist-non-react-statics";
import { withNavigation } from "react-navigation";

/**
* This Higher Order Component (HOC) unmounts a component when it looses
* navigation 'focus' - e.g. it will unmount when you navigate away from it.
* Unlike the react-navigation `withNavigationFocus` it will unmount on the
* `didBlur` event instead of `willBlur` - i.e. the unmount will happen at the
* end of any navigation transition. This is necessary because unmounting the
* camera component is expensive and can lock-up the transition animation.
* This Higher Order Component (HOC) that provides an `isFocussed` prop to the
* wrapped component, similar to
* [`withNavigationFocus`](https://reactnavigation.org/docs/en/with-navigation-focus.html)
* from `react-navigation` but in contrast to that, this one considers the
* screen to be focussed until it finishes animating out, as opposed to until
* when is starts animating out.
*/
export default function withNavigationFocus(Component) {
class ComponentWithNavigationFocus extends React.Component {
Expand Down Expand Up @@ -41,14 +40,12 @@ export default function withNavigationFocus(Component) {
}

render() {
return this.state.isFocused ? (
return (
<Component
{...this.props}
isFocused={this.state.isFocused}
ref={this.props.onRef}
/>
) : (
<View />
);
}
}
Expand Down

0 comments on commit 840ebab

Please sign in to comment.