Skip to content

Commit d9fc335

Browse files
committed
feat: isTablet function
1 parent d998319 commit d9fc335

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

lib/helpers/device/DeviceInfo.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ const vw = WindowWidth / 100;
4545
const vmin = Math.min(vh, vw) || vh;
4646
const vmax = Math.max(vh, vw) || vw;
4747

48+
/**
49+
* Determines if the current device is a tablet.
50+
* Uses a singleton approach to avoid re-evaluating each time.
51+
*/
52+
const determineIsTablet = (): boolean => {
53+
const { width, height } = Dimensions.get("window");
54+
const aspectRatio = height / width;
55+
56+
const minTabletWidth = 600; // dp
57+
const maxPhoneAspectRatio = 1.6; // Typical phone aspect ratio
58+
59+
return (
60+
(isAndroid || isIOS) &&
61+
(width >= minTabletWidth || aspectRatio <= maxPhoneAspectRatio)
62+
);
63+
};
64+
65+
// Singleton value to prevent recalculating multiple times
66+
const isTablet: boolean = determineIsTablet();
67+
4868
export {
4969
vh,
5070
vw,
@@ -63,5 +83,6 @@ export {
6383
WindowScale,
6484
WindowFontScale,
6585
PlatformVersion,
86+
isTablet,
6687
getDeviceLanguage,
6788
};

lib/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
ScreenFontScale,
1414
WindowWidth,
1515
WindowHeight,
16+
isTablet,
1617
WindowScale,
1718
WindowFontScale,
1819
PlatformVersion,
@@ -44,6 +45,7 @@ export {
4445
ScreenMax,
4546
isIOS,
4647
isAndroid,
48+
isTablet,
4749
ScreenWidth,
4850
ScreenHeight,
4951
ScreenScale,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@freakycoder/react-native-helpers",
3-
"version": "2.4.0",
3+
"version": "2.5.0",
44
"description": "All helpers in one; iPhone series support, dimensions helper, hasNotch helper, normalize text helper and text helpers for React Native with very easy use",
55
"keywords": [
66
"ios",

0 commit comments

Comments
 (0)