Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@patwoz/react-navigation-is-focused-hoc
Advanced tools
Ready to use solution using HOC to expose props.isFocused for react-navigation. No Redux needed.
This is a quick, ready to use solution using HOC to expose props.isFocused
. No Redux needed
react-navigation
@patwoz/react-navigation-is-focused-hoc
from npmyarn add @patwoz/react-navigation-is-focused-hoc
or
npm install --save @patwoz/react-navigation-is-focused-hoc
To see more of the react-navigation-is-focused-hoc
in action, you can check out the source in ExampleNavigation folder.
app.js
import React from 'react'
import { StackNavigator } from 'react-navigation'
import { updateFocus, getCurrentRouteKey } from '@patwoz/react-navigation-is-focused-hoc'
import MyScreenView from './screens/myScreenView'
// navigation
const AppNavigator = StackNavigator({
MyScreenView: { screen: MyScreenView },
}, {
initialRouteName: 'MyScreenView',
})
export default class App extends React.Component {
render() {
return (
<AppNavigator
onNavigationStateChange={(prevState, currentState) => {
// If you want to ignore the state changed from `DrawerNavigator`, use this:
/*
if (/^Drawer(Open|Close|Toggle)$/.test(getCurrentRouteKey(newState)) === false) {
updateFocus(newState);
return;
}
*/
updateFocus(currentState)
}}
/>
)
}
}
myScreenView.js
import React from 'react'
import PropTypes from 'prop-types'
import {
View,
Text,
} from 'react-native'
import { withNavigationFocus } from '@patwoz/react-navigation-is-focused-hoc'
class MyScreenView extends React.Component {
static propTypes = {
isFocused: PropTypes.bool.isRequired,
focusedRouteKey: PropTypes.string.isRequired,
};
componentWillReceiveProps(nextProps) {
if (!this.props.isFocused && nextProps.isFocused) {
// screen enter (refresh data, update ui ...)
}
if (this.props.isFocused && !nextProps.isFocused) {
// screen exit
}
}
shouldComponentUpdate(nextProps) {
// Update only once after the screen disappears
if (this.props.isFocused && !nextProps.isFocused) {
return true;
}
// Don't update if the screen is not focused
if (!this.props.isFocused && !nextProps.isFocused) {
return false;
}
// Update the screen if its re-enter
return !this.props.isFocused && nextProps.isFocused;
}
render() {
if (!this.props.isFocused /*&& this.props.focusedRouteKey.indexOf('Drawer') !== 0*/) {
return null;
}
return (
<View>
{this.props.isFocused
? <Text>I am focused</Text>
: <Text>I am not focused</Text>
}
</View>
)
}
}
export default withNavigationFocus(MyScreenView)
Thanks to Adam (@skevy), Mike (@grabbou), Satyajit (@satya164) and others for the react-navigation
module
FAQs
Ready to use solution using HOC to expose props.isFocused for react-navigation. No Redux needed.
The npm package @patwoz/react-navigation-is-focused-hoc receives a total of 1 weekly downloads. As such, @patwoz/react-navigation-is-focused-hoc popularity was classified as not popular.
We found that @patwoz/react-navigation-is-focused-hoc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.