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

Is this package really not needed anymore? (And why?) #71

Open
JeffreyVanelderenACA opened this issue Nov 9, 2022 · 4 comments
Open

Comments

@JeffreyVanelderenACA
Copy link

React-native-modal still references to use this package in their ReadMe

@Sunhat
Copy link
Owner

Sunhat commented Dec 13, 2022

@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.

@KevinvdBurg
Copy link

I had the same feeling as @JeffreyVanelderenACA, I was looking for an alternative but could not find any.

@lyswhut
Copy link

lyswhut commented Mar 21, 2023

Any news?

@finnmerlett
Copy link

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 onLayout prop's call argument e.nativeEvent.layout.

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>
  );
}

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

5 participants