Home > Enterprise >  What is the React Native alternative to flutter_screenutil?
What is the React Native alternative to flutter_screenutil?

Time:09-14

I have been a flutter developer for 2 years and I'm moving to React Native for a particular project. I am wondering if is there a similar package like flutter_screenutil for React Native?

CodePudding user response:

So with what the doc says

A flutter plugin for adapting screen and font size.Let your UI display a reasonable layout on different screen sizes!

This in react native doesnt required an additional package, its already provided by React native :)

https://reactnative.dev/docs/pixelratio

Check the above link , you can see documentation on how to achieve pixel density based on devices

https://snack.expo.dev/@gaurav1995/pixelratio-example

check my snack here

You need to import like

 import { Image, PixelRatio, ScrollView, StyleSheet, Text, View } from "react-native";

And use it like this

var image = getImage({
  width: PixelRatio.getPixelSizeForLayoutSize(200),
  height: PixelRatio.getPixelSizeForLayoutSize(100)
});
<Image source={image} style={{ width: 200, height: 100 }} />;

Hope it helps. feel free for doubts

  • Related