Open LucasMallmann opened 4 years ago
I would like to see that feature as well. I am using hooks and I really don't want to use class-based components.
im faceing this issue too and my whole app is build with funcational componants please add the support
same
See my pull request: PR https://github.com/marudy/react-native-responsive-screen/pull/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 😃
the error for that.setState is stil here , im also using hooks
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'
}
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 methoduseState
from class components.I guess that extending the listener to functional components would be great ;)