1

Currently I have this:

const ButtonStyles = {
    color: 'red',
}

But I want to add a Media Query for mobile, would it look something like this?:

const ButtonStyles = {
    color: 'red',
    '@media (max-width: 900px)': {
        color: 'blue',
    }
}

If the syntax is not in this format, then how is it supposed to be done?

1

2 Answers 2

1

Give a try.

https://github.com/kasinskas/react-native-media-query Work just like RN StyleSheet, but with queries.

https://github.com/yocontra/react-responsive Work with functions inside regular RN StyleSheet

An eg. with natives StyleSheet, Platform and React-Responsive and variables.

import { StyleSheet, Platform } from 'react-native';
import { useMediaQuery } from 'react-responsive';

export const STYLES = StyleSheet.create({

  content: (setup) => {
    const justifyTo = setup?.justify ? setup.justify : 'flex-start';

    return {
      justifyContent: justifyTo,
      ...Platform.select({
        web: {
          width: useMediaQuery({ maxWidth: 767 }) ? '100vw' : '70vw',

          maxWidth: 1280,
          marginHorizontal: 'auto',
          marginVertical: 'auto',
        },
      }),
    };
  }

});
Sign up to request clarification or add additional context in comments.

Comments

0

According to this discussion You cannot use Media queries with react css objects. You must use stylesheets with class names or other external modules like styled components.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.