marudy / react-native-responsive-screen

Make React Native views responsive for all devices with the use of 2 simple methods
MIT License
1.55k stars 141 forks source link

[Solved] Issue when using listenOrientationChange in hooks #69

Open hoanglam10499 opened 4 years ago

hoanglam10499 commented 4 years ago

Solved:

const [ state, setstate ] = React.useState(null); React.useEffect(() => { listenOrientationChange(setstate); return () => { removeOrientationListener(); };}, []);

And Package:

if (that.setState == null) { that(screenWidth < screenHeight ? 'portrait' : 'landscape'); } else { that.setState({ orientation: screenWidth < screenHeight ? 'portrait' : 'landscape' });}

Hope it helps everyone

EzeMortal commented 4 years ago

Thank you bro! Working perfectly. Can you do a PR?

hoanglam10499 commented 4 years ago

@EzeMortal yes i did it

Marzdor commented 4 years ago

Can this get merged plz, it is really useful. #70

anisharya16 commented 4 years ago

Solved:

const [ state, setstate ] = React.useState(null); React.useEffect(() => { listenOrientationChange(setstate); return () => { removeOrientationListener(); };}, []);

And Package:

if (that.setState == null) { that(screenWidth < screenHeight ? 'portrait' : 'landscape'); } else { that.setState({ orientation: screenWidth < screenHeight ? 'portrait' : 'landscape' });}

Hope it helps everyone

Thanks a lot, It helped.

Marzdor commented 4 years ago

@anisharya16 I forked it and added the change.

https://github.com/Marzdor/react-native-responsive-screen I plan to just use the fork until he merges the change

sammysium commented 3 years ago

will this one be merged in? it's been months.