0.11.0 • Published 1 month ago

@fluentui-react-native/theme v0.11.0

Weekly downloads
259
License
MIT
Repository
github
Last release
1 month ago

@fluentui-react-native/theme

Code support for working with the themes defined in @fluentui-react-native/theme-types. This includes a ThemeReference class and a ThemeProvider implementation that works with the references.

ThemeReference

A class that constructs a Theme based upon a either another fully built Theme or a parent ThemeReference, then layers in PartialTheme fragments, or ThemeTransform functions. It then provides the ability to invalidate, the ability to update the fragments, and the ability to listen to changes for the theme.

Creating a ThemeReference

A reference is created by combination a base with zero or more recipes.

  • Base - either a Theme or another ThemeReference
  • Recipe - either a PartialTheme or a function of the form (parent: Theme) => PartialTheme

The ThemeReference supports the following methods:

  • theme - get the built theme, implemented as a getter to dynamically create it when queried
  • invalidate() - let the reference know something has changed, this will replay the recipies to generate a new theme
  • update(...recipes) - update the recipes used to build the theme, will also invalidate the reference
  • addOnThemeChanged(listener) - add a listener to be notified of theme changes
  • removeOnThemeChanged(listener) - remove the listener

In practice this can be used to implement a theme, that has some values coming from external calls (maybe to a native module), and rebuilds itself when those values change. This might look something like:

import { defaultFluentTheme } from '@fluentui-react-native/default-theme';
import { ThemeReference } from '@fluentui-react-native/theme';

// in this case wrapping the reference in a function makes it easy to encapsulate the invalidating
export const createMyCustomTheme = () => {
  // create the reference
  const themeRef = new ThemeReference(
    // base it on the default fluent theme
    defaultFluentTheme,
    // mix in some constant values to override
    {
      colors: {
        // stuff here
      },
    },
    // make some outside calls to get some values
    () => {
      // query a body background from somewhere else
      const bodyBackground = checkSomeOutsideValue();
      return {
        colors: {
          bodyBackground,
        },
      };
    },
  );
  // register a change handler that invalidates the reference
  listenForOutsideValueChange(() => {
    themeRef.invalidate();
  });
  return themeRef;
};

ThemeProvider

This is a standard context provider that takes theme references as inputs for the theme prop.

0.11.0

1 month ago

0.10.8

3 months ago

0.10.7

3 months ago

0.10.6

4 months ago

0.10.5

5 months ago

0.10.3

5 months ago

0.10.4

5 months ago

0.10.2

5 months ago

0.10.1

5 months ago

0.9.2

7 months ago

0.9.1

10 months ago

0.9.4

7 months ago

0.9.3

7 months ago

0.10.0

6 months ago

0.9.0

12 months ago

0.8.5

12 months ago

0.8.4

1 year ago

0.8.3

1 year ago

0.8.2

1 year ago

0.8.1

1 year ago

0.7.21

1 year ago

0.7.20

1 year ago

0.7.19

1 year ago

0.7.18

1 year ago

0.7.17

1 year ago

0.8.0

1 year ago

0.7.11

1 year ago

0.7.10

1 year ago

0.7.9

1 year ago

0.7.13

1 year ago

0.7.12

1 year ago

0.7.8

2 years ago

0.7.7

2 years ago

0.7.15

1 year ago

0.7.14

1 year ago

0.7.16

1 year ago

0.7.4

2 years ago

0.7.3

2 years ago

0.7.6

2 years ago

0.7.5

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.7.0

2 years ago

0.6.9

2 years ago

0.6.10

2 years ago

0.6.11

2 years ago

0.6.7

2 years ago

0.6.8

2 years ago

0.6.6

2 years ago

0.6.3

2 years ago

0.6.2

2 years ago

0.6.5

2 years ago

0.6.4

2 years ago

0.6.1

2 years ago

0.5.23

3 years ago

0.6.0

3 years ago

0.5.22

3 years ago

0.5.21

3 years ago

0.5.20

3 years ago

0.5.19

3 years ago

0.5.18

3 years ago

0.5.17

3 years ago

0.5.16

3 years ago

0.5.15

3 years ago

0.5.14

3 years ago

0.5.13

3 years ago

0.5.12

3 years ago

0.5.11

3 years ago

0.5.10

3 years ago

0.5.8

3 years ago

0.5.7

3 years ago

0.5.9

3 years ago

0.5.6

3 years ago

0.5.5

3 years ago

0.5.4

3 years ago

0.5.3

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.1

3 years ago

0.4.0

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago