-
Notifications
You must be signed in to change notification settings - Fork 131
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
Is this package really not needed anymore? (And why?) #71
Comments
@JeffreyVanelderenACA Thanks for letting me know. I'll look at testing this on the latest RN version, but likely in the New Year. I've a lot of different on-going projects that require my attention. |
I had the same feeling as @JeffreyVanelderenACA, I was looking for an alternative but could not find any. |
Any news? |
I found a solution that seemed to work pefectly for me here: facebook/react-native#23693 (comment) It essentially boils down to - load a full-size view component at your app root, then get the dimensions from the Here's a minimal TypeScript hook for ease of use: import React, { useContext, useState } from "react";
import { Dimensions, LayoutRectangle, View } from "react-native";
type LayoutSize = Pick<LayoutRectangle, "width" | "height">;
const ScreenDimensionsContext = React.createContext<LayoutSize | null>(null);
export const useActualDimensions = () => {
const dimensions = useContext(ScreenDimensionsContext);
if (!dimensions) throw new Error("useDimensions hook must be used inside provider");
return dimensions;
};
interface ScreenDimensionsProviderProps {
children: React.ReactNode;
}
export function ActualDimensionsProvider({ children }: ScreenDimensionsProviderProps) {
const [dimensions, setDimensions] = useState<LayoutSize>(Dimensions.get("window"));
return (
<ScreenDimensionsContext.Provider value={dimensions}>
<View style={{flex: 1}} onLayout={(e) => setDimensions(e.nativeEvent.layout)}>
{children}
</View>
</ScreenDimensionsContext.Provider>
);
} |
React-native-modal still references to use this package in their ReadMe
The text was updated successfully, but these errors were encountered: