UNPKG

@applicaster/zapp-react-native-utils

Version:

Applicaster Zapp React Native utilities package

22 lines (18 loc) 715 B
import { Dimensions, Platform } from "react-native"; import NativeDeviceInfo from "react-native/Libraries/Utilities/NativeDeviceInfo"; import { Context } from "../../types"; /** * Returns initial dimension or updated * iOS has defect when sometimes Dimensions.get returning wrong values, while * NativeDeviceInfo.getConstants().Dimensions always returns correct * * @param context - window or screen * @returns Value for the dimension */ export const getInitialDimensions = (context: Context) => { const dimension = Dimensions.get(context); if (Platform.OS === "ios" && dimension.width === dimension.height) { return NativeDeviceInfo.getConstants().Dimensions[context]; } return dimension; };