You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Library for Jetpack Compose providing wrappers to apply **Material 3** (M3) themes to **Material 2** (M2) components and vice-versa.
4
+
5
+
## Features
6
+
- Provides wrapper composables that take the color, typography and shape values from the applied M2/M3 theme and maps them onto a M3/M2 theme.
7
+
8
+
- Use existing Compose components and libraries built with M2 in your M3 project, and your theme will be applied.
9
+
10
+
- Use new M3 components in your existing M2 project.
11
+
12
+
- Migrate parts of your UI or migrate your theme without worrying about compatibility with old or new Compose libraries and components.
13
+
14
+
## Basic Usage
15
+
16
+
Simply wrap a Material 2 composable with a `M2Wrapper` and the Material 3 theme will be applied:
17
+
18
+
```kotlin
19
+
MaterialTheme { // Material 3 Theme
20
+
M2Wrapper { // Wrap with a Material 2 Theme Wrapper
21
+
// Insert Material 2 components here...
22
+
ExampleM2Component()
23
+
}
24
+
}
25
+
```
26
+
27
+
Material 3 composables can likewise be wrapped with a `M3Wrapper` to apply the Material 2 Theme:
28
+
```kotlin
29
+
MaterialTheme { // Material 2 Theme
30
+
M3Wrapper { // Wrap with a Material 3 Theme Wrapper
31
+
// Insert Material 3 components here...
32
+
ExampleM3Component()
33
+
}
34
+
}
35
+
```
36
+
37
+
## Usage
38
+
39
+
### Best Practice
40
+
The library is intended for use with existing custom built components and the wide variety of component libraries available online, in order to increase compatibility and theming support in existing projects and outdated libraries.
41
+
42
+
It aims to solve some of the migration issues outlined in the [Android Developers documentation](https://developer.android.com/jetpack/compose/designsystems/material2-material3).
43
+
44
+
As default M2 components *(such as buttons, the top app bar, and other controls)* use different color roles and shape sizes than their M3 counterparts, they will not look exactly the same even with the wrapper applied (and vice-versa). Therefore it is recommended to simply use the default low-level components of the intended theme where possible, and only use the wrapper for more complex components.
45
+
46
+
The above linked resource explains the difference between the two design systems and their compatibility in greater detail.
47
+
48
+
### Customisation
49
+
By default, the wrappers map the colors and shapes that allow for components to best match their counterparts in the current theme.
50
+
51
+
If this does not work as expected, the library also provides the `exactColors()`, `exactColorScheme()` and `exactShapes()` mappings which map values 1:1 to their named counterparts in the current theme, which may be more intuitive depending on the component.
52
+
53
+
These can be specified by modifying the properties of the wrapper:
The `M2WrapperDefaults` and `M3WrapperDefaults` provide the default `colors()` / `colorScheme()`, `shapes()` and `typography()` mappings to allow for complete customisation.
76
+
77
+
This is useful for ensuring the correct colors etc. are used for components that lack color customisation.
78
+
79
+
> For best results, use the wrapper as close to the component as possible to allow mappings to be customised per component.
80
+
81
+
You can also specify your own `Colors` / `ColorScheme`, `Shapes` and `Typography` objects, however this is not recommended.
0 commit comments