yamankatby / react-native-material

Modular and customizable Material Design UI components for React Native
https://rn-material.js.org
MIT License
228 stars 38 forks source link

Theming #33

Open widianapw opened 2 years ago

widianapw commented 2 years ago

Capability to set the theme for the whole application

yamankatby commented 2 years ago

Hi Widiana, Thank you for reporting this issue. Indeed this is not a feature request since there is already a way to do this. It just needs to be added to the documentation.

You have to wrap your app in the Provider component:

import { Provider, defaultTheme } from "@react-native-material/core";

const App = () => (
  <Provider
    theme={{
      // extend the default theme
      ...defaultTheme,
      palette: {
        ...defaultTheme.palette,
        // override the primary color
        primary: { main: "red", on: "white" },
      },
    }}
  >
    ...
  </Provider>
);

export default App;

If you have time and you would like to help please make a PR to the documentation repo and add Theming page.

Pika-Pool commented 2 years ago

@yamankatby , could you please explain what is the meaning of main and on properties in palette, and when do we use each of them?

yamankatby commented 2 years ago

Hi @Pika-Pool,

The main and on terms are defined by Material design 2, see https://material.io/design/color/the-color-system.html#color-theme-creation.

Simply the main is the color itself and the on is the color to be used on top of the color

Group 8 .

Drealler commented 2 years ago

Hi, I tried this solution and got this error in typescript. Looks like the children is missing in the type definition.

image

Edit: Is npm version outdated?

Iryn-e commented 2 years ago

Hi, I tried this solution and got this error in typescript. Looks like the children is missing in the type definition.

image

Edit: Is npm version outdated?

I'm having the same issue when using typescript as the base of the application when it comes to wrapping my entire app with (As in I see the same error message as @Drealler here). However while I am able to change the color of the appbar, I don't think there is a way of easily changing the background color of list items, manually or otherwise. Here is what I get on an appbar and a list of items with the provider as:

        <Provider
            theme={{
                ...defaultTheme,
                palette: {
                    ...defaultTheme.palette,
                    primary: {main: "red", on: "yellow"}

                }
            }}
        >

![1662482504010](https://user-images.githubusercontent.com/76730458/188693886-3ed04ce5-e333-416a-9493-6aa1bcc0d3ac.JPEG =250x250)