Skip to content

Bug and potential changes? #2

Description

@karland

Hi, your library is rather nice. Thank you for the effort.

For my own purposes, I have made some (API and param) changes and wonder if you would be interested? I know, these are big changes. So, feel free to close.

  1. This seems to be a bug: it should read width instead of height as your are in landscape mode:
    https://github.com/applike/responsive-react/blob/eb601c0aa78492f359d387bd0291d43a252a94f5/src/utilResponsive.js#L64-L65

  2. In the README.md under ### Approach 2 and ### Additional helper function I suggest to
    import {...} from "react-responsive".

  3. I added constants

exportconstPORTRAIT="PORTRAIT"exportconstLANDSCAPE="LANDSCAPE"exportconstMOBILE="MOBILE"exportconstMOBILE_SMALL="MOBILE_SMALL"exportconstMOBILE_MEDIUM="MOBILE_MEDIUM"exportconstMOBILE_LARGE="MOBILE_LARGE"exportconstTABLET="TABLET"exportconstIPAD_PRO="IPAD_PRO"exportconstLAPTOP="LAPTOP"exportconstLAPTOP_SMALL="LAPTOP_SMALL"exportconstLAPTOP_MEDIUM="LAPTOP_MEDIUM"exportconstLARGE_SCREEN="LARGE_SCREEN"exportconstSUPER_LARGE_SCREEN="SUPER_LARGE_SCREEN"
  1. Update screen sizes of smartphones and take acount of laptops with 1920:
exportconstDeviceWidthObject={// MobileSmall: { max: 320, min: 0 },MOBILE_SMALL: {max: 480,min: 0},// e.g. iPhone4// MobileMedium: { max: 375, min: 321 },MOBILE_MEDIUM: {max: 640,min: 481},// e.g. iPhone5MOBILE_LARGE: {max: 767,min: 641},// e.g. Pixel 2, iPhone XTABLET: {max: 991,min: 768},LAPTOP_SMALL: {max: 1024,min: 992},// LaptopLarge: { max: 1440, min: 1025 },LAPTOP_MEDIUM: {max: 1440,min: 1025},// LargerThanLaptop: { max: 2560, min: 1441 },LARGE_SCREEN: {max: 2560,min: 1441},SUPER_LARGE_SCREEN: {max: 999999,min: 2561}}
  1. You can save 1/3 of the code in utilResponsive.js if you always virtually swap the device into landscape mode to determine its size.

  2. I have made boolean values. e.g. isMobileDevice, boolean and not a function

exportconstisMobileDevice=(()=>{constdeviceInformation=getDeviceTypeInfo()returndeviceInformation.deviceType==="Mobile"})()
  1. OPTIONAL: Added some additional precision booleans:
import{LANDSCAPE,LAPTOP_SMALL,LAPTOP_MEDIUM,LARGE_SCREEN,SUPER_LARGE_SCREEN,MOBILE_SMALL,MOBILE_MEDIUM,MOBILE_LARGE,TABLET,IPAD_PRO,getDeviceTypeInfo}from"./utilResponsive"constsizeDevice=()=>{const{deviceTypeVariant: deviceType, orientation }=getDeviceTypeInfo()constisLandscape=orientation===LANDSCAPEconstisPortrait=!isLandscapeconstisSmartphoneSmall=deviceType===MOBILE_SMALLconstisSmartphoneMedium=deviceType===MOBILE_MEDIUMconstisSmartphoneLarge=deviceType===MOBILE_LARGEconstisMaxSmartphone=isSmartphoneSmall||isSmartphoneMedium||isSmartphoneLargeconstisSuperLargeScreen=deviceType===SUPER_LARGE_SCREENconstisMinLargeScreen=deviceType===LARGE_SCREEN||isSuperLargeScreenconstisMinLaptop=deviceType===LAPTOP_SMALL||deviceType===LAPTOP_MEDIUM||isMinLargeScreenconstisMinTablet=deviceType===TABLET||deviceType===IPAD_PRO||isMinLaptopconstisMinSmartphoneLarge=isSmartphoneLarge||isMinLaptopconstisMinSmartphoneMedium=isSmartphoneMedium||isSmartphoneLargereturn{
isPortrait,
isLandscape,
isSmartphoneSmall,
isSmartphoneMedium,
isSmartphoneLarge,
isMaxSmartphone,
isMinSmartphoneMedium,
isMinSmartphoneLarge,
isMinTablet,
isMinLaptop,
isMinLargeScreen,
isSuperLargeScreen
}}

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions