UNPKG

@raahimkhan23/react-native-responsive-utils

Version:

A lightweight utility package for making React Native apps responsive across different screen sizes. It allows you to scale widths, heights, fonts, and images based on a configurable base screen size, enabling consistent layouts on different devices. The

93 lines 4.09 kB
/** * base screen width and height (iPhone 16 Pro Portrait mode) */ declare let BASE_SCREEN_WIDTH: number; declare let BASE_SCREEN_HEIGHT: number; declare let CURRENT_SCREEN_WIDTH: number; declare let CURRENT_SCREEN_HEIGHT: number; /** * updates the base screen width and height used for scaling * @param width - the new base screen width * @param height - the new base screen height */ declare const setBaseScreenSize: (width: number, height: number) => void; /** * listens for orientation changes and updates the orientation state accordingly * @param setOrientation - React setState function to update orientation ('portrait' or 'landscape') * @returns void */ declare const listenOrientationChange: (setOrientation: (value: "portrait" | "landscape") => void) => void; /** * removes the orientation change listener if it exists * @returns void */ declare const removeOrientationListener: () => void; /** * scales a given width based on the current screen width and base screen width * @param width - the original width to scale * @returns the scaled width */ declare const scaleWidth: (width: number) => number; /** * scales a given height based on the current screen height and base screen height * @param height - the original height to scale * @returns the scaled height */ declare const scaleHeight: (height: number) => number; /** * scales a given image width based on the current screen width and base screen width, rounded to the nearest pixel * @param width - the original image width to scale * @returns the scaled image width */ declare const scaleImageWidth: (width: number) => number; /** * scales a given image height based on the scaled image width and original aspect ratio, rounded to the nearest pixel * @param width - the original image width (to determine the aspect ratio) * @param height - the original image height to scale * @returns the scaled image height */ declare const scaleImageHeight: (width: number, height: number) => number; /** * minimum and maximum clamping values for font scaling */ declare let MIN_FONT_SCALE: number; declare let MAX_FONT_SCALE: number; /** * updates the minimum and maximum limits for font scaling clamp values * @param minFontScale - minimum scale clamp for fonts * @param maxFontScale - maximum scale clamp for fonts */ declare const setFontScaleLimits: (minFontScale: number, maxFontScale: number) => void; /** * scales a given font size based on the smaller screen dimension with clamping, rounded to the nearest pixel * @param fontSize - the original font size * @returns the scaled and clamped font size */ declare const scaleFont: (fontSize: number) => number; /** * defines supported iPhone models for dimension comparison */ type IphoneModel = 'iPhoneSE' | 'iPhone13Mini' | 'iPhone16Pro' | 'iPhone16ProMax'; /** * checks if the current device's longest side matches the given iPhone model longest side * @param model - the iPhone model name * @returns true if current screen's longest side matches the given iPhone model's longest side, otherwise false */ declare const isIphoneModel: (model: IphoneModel) => boolean; /** * converts the given width percentage to device independent pixels (dp) * @param widthPercent - percentage of the screen's width (0 – 100) * @returns the corresponding dp based on the current device's screen width */ declare const wp: (widthPercent: number) => number; /** * converts the given height percentage to device independent pixels (dp) * @param heightPercent - percentage of the screen's height (0 – 100) * @returns the corresponding dp based on the current device's screen height */ declare const hp: (heightPercent: number) => number; /** * exports constants and utility functions */ export { BASE_SCREEN_WIDTH, BASE_SCREEN_HEIGHT, CURRENT_SCREEN_WIDTH, CURRENT_SCREEN_HEIGHT, MIN_FONT_SCALE, MAX_FONT_SCALE, setBaseScreenSize, listenOrientationChange, removeOrientationListener, scaleWidth, scaleHeight, scaleImageWidth, scaleImageHeight, setFontScaleLimits, scaleFont, isIphoneModel, wp, hp, }; //# sourceMappingURL=index.d.ts.map