Giter VIP home page Giter VIP logo

Comments (5)

robertherber avatar robertherber commented on May 2, 2024 5

I just did a direct implementation that I think is stable that doesn't depend on anything but the useNavigation() hook, maybe it can be of help:

import { useState, useEffect } from 'react';
import { useNavigation } from 'react-navigation-hooks';


const useIsFocused = () => {
  const navigation = useNavigation(),
        [isFocused, setFocused] = useState(navigation.isFocused());

  useEffect(() => {
    const didBlur = () => setFocused(false);
    const didFocus = () => setFocused(true);

    const blurSubscription = navigation.addListener('didBlur', didBlur);
    const focusSubscription = navigation.addListener('didFocus', didFocus);

    return () => {
      blurSubscription.remove();
      focusSubscription.remove();
    };
  }, []); //eslint-disable-line

  return isFocused;
};

export default useIsFocused;

from hooks.

slorber avatar slorber commented on May 2, 2024 2

Hi,

I can confirm, it's an existing bug in the event hook which affect focus as well.
Made this PR long time ago to fix this: #8

I'd like to get this fixed soon, but need to improve the lib's DX first. There's no tests and no example app. I've a pending PR which does not work yet for the example app: #28

This package was written at a time where RN didn't even have hooks. Will try to make this a viable lib over time but quite busy atm :/

from hooks.

slorber avatar slorber commented on May 2, 2024 1

Will be fixed by #38, going to merge/release soon

from hooks.

slorber avatar slorber commented on May 2, 2024

@robertherber what is useNavigationFocus() ?

Actually I'm looking at the code and don't see it. There is "useFocusState().isFocused" and according to my tests and the code I'm reading, it's working.

Is useNavigationFocus() a custom hook you built on events? I suspect you have a custom hook, and you initialize focus state to false, and the initial focus event is not fired on mount (which I'm currently correcting)

from hooks.

slorber avatar slorber commented on May 2, 2024

should be fixed by release 1.0.3 and #38, please tell me if everything works

from hooks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.