Class: MaterialColor
Defined in: modules/material-color/MaterialColor.ts:45
Build Material color scheme to map dynamic color, use as fallback colors, or implement a branded theme
All the science have been done by @material/material-color-utilities, except a module of how to get source color from image's bitmap for non Web platform.
There are ways to build material color with this class. You can choose one of these ways
- Instantiate this class with Hex color code in the constructor argument
- Quickly build it from an hex color with the
MaterialColor.fromSourceColorHexIntstatic method - You can also use the
MaterialColor.fromSourceImageorMaterialColor.fromSourceImageUristatic method to get material color
Implements
Constructors
Constructor
new MaterialColor(
sourceColor,options?):MaterialColor
Defined in: modules/material-color/MaterialColor.ts:214
Parameters
sourceColor
string
Seed hex color for building a Material color scheme to map dynamic color
options?
Returns
MaterialColor
Methods
dynamicScheme()
dynamicScheme():
DynamicScheme
Defined in: modules/material-color/MaterialColor.ts:197
You can get the original DynamicScheme result from @material/material-color-utilitites
Returns
DynamicScheme
fromSourceColorHexInt()
staticfromSourceColorHexInt(hexInt,options?):MaterialColor
Defined in: modules/material-color/MaterialColor.ts:156
Build Material Color from a hex color code in decimal or hexadecimal,
e.g. 0xFFFFFF, 16777215 (white in decimal)
Parameters
hexInt
number
options?
Returns
MaterialColor
fromSourceImage()
staticfromSourceImage(source,options?,processingOptions?):Promise<MaterialColor>
Defined in: modules/material-color/MaterialColor.ts:103
Get the source color from an image and return MaterialColor in promise.
If you wish to get the source color only from an image, you can use ImageUtils.sourceColorFromImageUri(), or ImageUtils.sourceHexColorFromImageUri()
If you already have the URI, for instance you get an image from a file/document picker, or an online image, you can use MaterialColor.fromSourceImageUri
Parameters
source
ImageSourcePropType
options?
processingOptions?
SourceColorFromImageProcessingOptions
Returns
Promise<MaterialColor>
Example
import {
MaterialColor,
} from "react-native-material-color"
function yourMethod() {
MaterialColor
.sourceColorFromImage(
// you can still use the ESM import
require("./your-image.png"),
{
variant: MaterialColor.Variant.TONAL_SPOT,
}, // optional argument
{
timeout: 10000,
}, // optional argument
)
.then(materialColor => {
if(materialColor) {
// your logics here
}
})
.catch(err => {
// Thrown by
// - an timeout (provided in the third argument object)
// - your own AbortSignal (provided in the third argument object)
// - something from "@material/material-color-utilities"
})
}
Platform
Android
Platform
iOS
Platform
macOS
Platform
Web
fromSourceImageUri()
staticfromSourceImageUri(uri,options?,processingOptions?):Promise<MaterialColor>
Defined in: modules/material-color/MaterialColor.ts:134
Get the source color from an image uri and return MaterialColor in promise.
Similar as the MaterialColor.fromSourceImage, but you can provide the uri only, whether it's an online image, or local file uri that you get by importing a file, or file/gallery picker
Parameters
uri
string
options?
processingOptions?
SourceColorFromImageProcessingOptions
Returns
Promise<MaterialColor>
Platform
Android
Platform
iOS
Platform
macOS
Platform
Web
Properties
colorScheme
readonlycolorScheme:ColorScheme
Defined in: modules/material-color/MaterialColor.ts:168
Implementation of
MaterialColorInterface.colorScheme
contrastLevel
readonlycontrastLevel:number
Defined in: modules/material-color/MaterialColor.ts:172
Implementation of
MaterialColorInterface.contrastLevel
errorPalette
readonlyerrorPalette:ColorPaletteHex
Defined in: modules/material-color/MaterialColor.ts:187
Implementation of
MaterialColorInterface.errorPalette
neutralPalette
readonlyneutralPalette:ColorPaletteHex
Defined in: modules/material-color/MaterialColor.ts:189
Implementation of
MaterialColorInterface.neutralPalette
neutralVariantPalette
readonlyneutralVariantPalette:ColorPaletteHex
Defined in: modules/material-color/MaterialColor.ts:191
Implementation of
MaterialColorInterface.neutralVariantPalette
platform
readonlyplatform:Platform
Defined in: modules/material-color/MaterialColor.ts:174
Implementation of
MaterialColorInterface.platform
primaryPalette
readonlyprimaryPalette:ColorPaletteHex
Defined in: modules/material-color/MaterialColor.ts:181
Implementation of
MaterialColorInterface.primaryPalette
secondaryPalette
readonlysecondaryPalette:ColorPaletteHex
Defined in: modules/material-color/MaterialColor.ts:183
Implementation of
MaterialColorInterface.secondaryPalette
sourceColor
readonlysourceColor:string
Defined in: modules/material-color/MaterialColor.ts:166
Your original source color in hex code
Implementation of
MaterialColorInterface.sourceColor
specVersion
readonlyspecVersion:SpecVersion
Defined in: modules/material-color/MaterialColor.ts:176
Implementation of
MaterialColorInterface.specVersion
tertiaryPalette
readonlytertiaryPalette:ColorPaletteHex
Defined in: modules/material-color/MaterialColor.ts:185
Implementation of
MaterialColorInterface.tertiaryPalette
theme
readonlytheme:"light"|"dark"
Defined in: modules/material-color/MaterialColor.ts:170
Implementation of
variant
readonlyvariant:Variant
Defined in: modules/material-color/MaterialColor.ts:178
Implementation of
MaterialColorInterface.variant
ContrastLevelPresets
staticContrastLevelPresets:object
Defined in: modules/material-color/MaterialColor.ts:50
DEFAULT
readonlyDEFAULT:0=0.0
HIGH
readonlyHIGH:1=1.0
MEDIUM
readonlyMEDIUM:0.5=0.5
REDUCED
readonlyREDUCED:-1=-1.0
SourceImageException
staticSourceImageException: typeofSourceColorFromImageException=ImageUtils.SourceColorFromImageException
Defined in: modules/material-color/MaterialColor.ts:57
Variant
staticVariant: typeofVariant
Defined in: modules/material-color/MaterialColor.ts:47