Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orientation listeners don't work in functional components #65

Open
LucasMallmann opened this issue Feb 6, 2020 · 6 comments
Open

Orientation listeners don't work in functional components #65

LucasMallmann opened this issue Feb 6, 2020 · 6 comments

Comments

@LucasMallmann
Copy link

I was writing a functional component and I just don't know how to subscribe to the orientation changes. Since the method listenOrientationChange accepts a class instance and use the method useState from class components.

I guess that extending the listener to functional components would be great ;)

@AVATAR197
Copy link

I would like to see that feature as well. I am using hooks and I really don't want to use class-based components.

@mshafex
Copy link

mshafex commented Jul 12, 2020

im faceing this issue too and my whole app is build with funcational componants please add the support

@ahmedjaafar6
Copy link

same

@gregfenton
Copy link

gregfenton commented Aug 20, 2020

See my pull request: PR #83

It has updated docs and a hook example and everything. And the change to RNRS itself is pretty small. And adds a new feature 😃

@janpaulalmanoche
Copy link

the error for that.setState is stil here , im also using hooks

@tejfaster
Copy link

maybe we can change some code like :

const Orientation = () => {
const [dimensions, setDimensions] = useState({ window, screen });

useEffect(() => {
    const subscription = Dimensions.addEventListener(
        'change',
        ({ window, screen }) => {
            setDimensions({ window, screen });
        }
    );
    return () => subscription?.remove();
});
return dimensions.screen.height > dimensions.screen.width ? 'portrait' : 'landscape'

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants