NativeBase icon indicating copy to clipboard operation
NativeBase copied to clipboard

Responsiveness

Open pablohpsilva opened this issue 5 years ago • 11 comments

Describe the bug I'm using native-base + nextjs.

{[...Array(10).keys()].map((_, i) => 
    <Image
        key={`image-${i}`}
        source={{
          uri: imgSource,
        }}
        resizeMode="cover"
        height={{
          base: 220,
          sm: 210,
          md: 220,
          lg: 250,
          xlg: 250,
        }}
        width={{
          base: 155,
          sm: 145,
          md: 155,
          lg: 185,
          xlg: 185,
        }}
      />
}

The bug is the following:

  • If you start your build or refresh your browser, I always get the height 250 and width 250;
  • If I remove the xlg and refresh the page, the default height is 220 and width 155 (base value), no matter what screen I check (iphone size, for example), the lg, md, and sm sizes are being ignored;
  • If I put back the xlg and remove the base, then the value is height 250 and width 250, no matter what screen I check (iphone size, for example), the lg, md, and sm sizes are being ignored;

Overall: responsive breakpoints are not working. sm size is not enough for iphone display size.

OBS.: useMediaQuery has the very same problem on SSR

Platform

node: v16.5.0 npm: v7.20.0 yarn: v1.22.10 "native-base": "^3.0.7", "next": "latest", "react": "^17.0.2", "react-dom": "^17.0.2", "react-native-safe-area-context": "^3.3.0", "react-native-svg": "^12.1.1", "react-native-web": "^0.17.1", "styled-components": "^5.3.0", "styled-system": "^5.1.5"

pablohpsilva avatar Aug 26 '21 16:08 pablohpsilva

useMediaQuery has the very same problem on SSR

pablohpsilva avatar Aug 26 '21 17:08 pablohpsilva

FYI: native-base version 3.0.0 works pretty fine.

pablohpsilva avatar Aug 26 '21 17:08 pablohpsilva

Any progress there? It would be nice to generate a separate style with a real media queries for web specifically.

georgii-ivanov avatar Sep 10 '21 23:09 georgii-ivanov

https://www.npmjs.com/package/react-native-media-query

That might be an option. It would be nice if that would be possible to implement with styled-components as it uses internal global style definition from next.

georgii-ivanov avatar Sep 10 '21 23:09 georgii-ivanov

I've decided to stick with [email protected] for now. The responsiveness is much better and the latest version has nothing extra that's impacting me right now.

@georgii-ivanov I was also using this: use-breakpoint. It was flawless. But then I decided to move to [email protected] and I use whatever they provide.

pablohpsilva avatar Sep 11 '21 06:09 pablohpsilva

I've decided to stick with [email protected] for now. The responsiveness is much better and the latest version has nothing extra that's impacting me right now.

@georgii-ivanov I was also using this: use-breakpoint. It was flawless. But then I decided to move to [email protected] and I use whatever they provide.

Bro really? I use "native-base": "3.2.1-rc.1", when I first load the web page, it just use the mobile layout AKA whatever I code for mobile, but all the size, direction, width, height I coded for lg, xl (all this for big screen) is ignored, it just look like layout for mobile.

When first reach the website in PC browser (insert the url and load the webpage), all it appeared is just like what I code for mobile. Can you help?

I have describe the issue here, https://github.com/GeekyAnts/NativeBase/issues/4200#issuecomment-953984097 do you mind to take a look?

kenchoong avatar Oct 28 '21 16:10 kenchoong

@kenchoong Responsive props currently won't work with NextJS or Server side rendering as Reach Native Web currently doesn't support media-queries in stylesheet so we're relying on RN's dimension API which can't return device dimension on server. We have a work-in-progress media query implementation for this, that should solve this issue. For now, I'd recommend wrapping your entire app or only responsive styled component with below component.

const ClientOnly = ({children}) => {
    const [mounted, setMounted] = React.useState(false);

    React.useEffect({
        setMounted(true);
    }, [])
 
    return mounted ? children : null;
}
// Use it like below

<NativeBaseProvider>
    <ClientOnly>
        <App />
    </ClientOnly>
</NativeBaseProvider>

I know this is just a workaround for now. Once we've the stable version of media-query implementation up, this workaround won't be needed. It would be great if RNW supports media-query just for min-width/max-width internally though.

@intergalacticspacehighway This worked!!! Thank you very much for your help. If this issue can be write into the docs I will very appreciate. Cant see this issue anywhere in docs

kenchoong avatar Oct 29 '21 10:10 kenchoong

Wow, this does actually fix a lot of bugs @intergalacticspacehighway. Very surprised by this. Please remember to close this issue once that PR is merged so we can all receive updates to remove your patch. 😄

cereallarceny avatar Dec 12 '21 20:12 cereallarceny

@kenchoong @georgii-ivanov @cereallarceny @pablohpsilva We fixed the above in the latest release of native-base(3.3.3). We are now implementing the styles using media query, this will also solve the flicker issue caused by forced re render. You can. checkout the implementation here.

vidhi499 avatar Jan 21 '22 06:01 vidhi499

@kenchoong Responsive props currently won't work with NextJS or Server side rendering as Reach Native Web currently doesn't support media-queries in stylesheet so we're relying on RN's dimension API which can't return device dimension on server. We have a work-in-progress media query implementation for this, that should solve this issue. For now, I'd recommend wrapping your entire app or only responsive styled component with below component.

const ClientOnly = ({children}) => {
    const [mounted, setMounted] = React.useState(false);

    React.useEffect({
        setMounted(true);
    }, [])
 
    return mounted ? children : null;
}
// Use it like below

<NativeBaseProvider>
    <ClientOnly>
        <App />
    </ClientOnly>
</NativeBaseProvider>

I know this is just a workaround for now. Once we've the stable version of media-query implementation up, this workaround won't be needed. It would be great if RNW supports media-query just for min-width/max-width internally though.

it defeats the purpose of SSR/Nextjs, might as well use CRA

marclester-tang avatar May 05 '22 03:05 marclester-tang