khevamann / rn-responsive-styles

Responsive styles for react-native and react-native-web
MIT License
39 stars 3 forks source link

Custom breakpoints are invalid #27

Closed 1280103995 closed 4 months ago

1280103995 commented 4 months ago

I created a new project on RN 0.73.4 and used the code in App.tsx in the example.

<BreakpointsProvider breakpoints={[1440, 1290, 1080, 828]}>
     <View style={styles.container}>
        <Text style={styles.text}>Device Size: {deviceSize}</Text>
        <Text style={styles.text}>Color: {DEVICE_COLOR[deviceSize]}</Text>
        {isLargerThan(DEVICE_SIZES.LG) && <Text>This text is rendered for large and Extra Large devices</Text>}
    </View>
</BreakpointsProvider>
1280103995 commented 4 months ago

I watched the tutorial again and solved my problem.

function MainComponent() {
  const styles = useStyles()
  const deviceSize = useDeviceSize()
  const { isLargerThan } = useSizeRender()

  return (
    <View style={styles.container}>
      <Text style={styles.text}>Device Size: {deviceSize}</Text>
      <Text style={styles.text}>Color: {DEVICE_COLOR[deviceSize]}</Text>
      {isLargerThan(DEVICE_SIZES.LG) && <Text>This text is rendered for large and Extra Large devices</Text>}
    </View>
  )
}

export default function App() {
  return (
    <BreakpointsProvider breakpoints={[1440, 1290, 1080, 828]}>
      <MainComponent/>
    </BreakpointsProvider>
  )
}