@onlynative/components 0.1.0-alpha.0 → 0.1.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { PropsWithChildren } from 'react';
3
3
  import { StyleProp, ViewStyle, ViewProps, FlexAlignType } from 'react-native';
4
4
  import { Edge } from 'react-native-safe-area-context';
5
- import { Theme } from '@onlynative/core';
5
+ import { MaterialTheme } from '@onlynative/core';
6
6
 
7
7
  interface LayoutProps extends PropsWithChildren {
8
8
  /**
@@ -18,7 +18,7 @@ interface LayoutProps extends PropsWithChildren {
18
18
  declare function Layout({ immersive, edges, children, style }: LayoutProps): react_jsx_runtime.JSX.Element;
19
19
 
20
20
  /** A theme spacing token name or a raw numeric value in dp. */
21
- type SpacingValue = keyof Theme['spacing'] | number;
21
+ type SpacingValue = keyof MaterialTheme['spacing'] | number;
22
22
  interface BoxProps extends ViewProps {
23
23
  /** Padding on all sides */
24
24
  p?: SpacingValue;
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/switch/index.ts
@@ -35,11 +25,31 @@ __export(switch_exports, {
35
25
  module.exports = __toCommonJS(switch_exports);
36
26
 
37
27
  // src/switch/Switch.tsx
38
- var import_MaterialCommunityIcons = __toESM(require("@expo/vector-icons/MaterialCommunityIcons"));
39
28
  var import_react = require("react");
40
29
  var import_react_native2 = require("react-native");
41
30
  var import_core = require("@onlynative/core");
42
31
 
32
+ // src/utils/icon.ts
33
+ var _MCIcons = null;
34
+ var _resolved = false;
35
+ function getMaterialCommunityIcons() {
36
+ if (!_resolved) {
37
+ _resolved = true;
38
+ try {
39
+ const mod = require("@expo/vector-icons/MaterialCommunityIcons");
40
+ _MCIcons = mod.default || mod;
41
+ } catch {
42
+ _MCIcons = null;
43
+ }
44
+ }
45
+ if (!_MCIcons) {
46
+ throw new Error(
47
+ "@expo/vector-icons is required for icon support. Install it with: npx expo install @expo/vector-icons"
48
+ );
49
+ }
50
+ return _MCIcons;
51
+ }
52
+
43
53
  // src/switch/styles.ts
44
54
  var import_react_native = require("react-native");
45
55
 
@@ -271,6 +281,7 @@ function Switch({
271
281
  }
272
282
  };
273
283
  const iconName = isSelected ? selectedIcon : unselectedIcon;
284
+ const MaterialCommunityIcons = iconName ? getMaterialCommunityIcons() : null;
274
285
  const iconSize = 16;
275
286
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
276
287
  import_react_native2.Pressable,
@@ -297,7 +308,7 @@ function Switch({
297
308
  {
298
309
  style: [styles.thumb, isDisabled ? styles.disabledThumb : void 0],
299
310
  children: iconName ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
300
- import_MaterialCommunityIcons.default,
311
+ MaterialCommunityIcons,
301
312
  {
302
313
  name: iconName,
303
314
  size: iconSize,
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/text-field/index.ts
@@ -35,11 +25,31 @@ __export(text_field_exports, {
35
25
  module.exports = __toCommonJS(text_field_exports);
36
26
 
37
27
  // src/text-field/TextField.tsx
38
- var import_MaterialCommunityIcons = __toESM(require("@expo/vector-icons/MaterialCommunityIcons"));
39
28
  var import_react = require("react");
40
29
  var import_react_native3 = require("react-native");
41
30
  var import_core = require("@onlynative/core");
42
31
 
32
+ // src/utils/icon.ts
33
+ var _MCIcons = null;
34
+ var _resolved = false;
35
+ function getMaterialCommunityIcons() {
36
+ if (!_resolved) {
37
+ _resolved = true;
38
+ try {
39
+ const mod = require("@expo/vector-icons/MaterialCommunityIcons");
40
+ _MCIcons = mod.default || mod;
41
+ } catch {
42
+ _MCIcons = null;
43
+ }
44
+ }
45
+ if (!_MCIcons) {
46
+ throw new Error(
47
+ "@expo/vector-icons is required for icon support. Install it with: npx expo install @expo/vector-icons"
48
+ );
49
+ }
50
+ return _MCIcons;
51
+ }
52
+
43
53
  // src/text-field/styles.ts
44
54
  var import_react_native2 = require("react-native");
45
55
 
@@ -298,6 +308,7 @@ function TextField({
298
308
  const isError = Boolean(error) || Boolean(errorText);
299
309
  const isFilled = variant === "filled";
300
310
  const hasLeadingIcon = Boolean(leadingIcon);
311
+ const MaterialCommunityIcons = leadingIcon || trailingIcon ? getMaterialCommunityIcons() : null;
301
312
  const { colors, styles } = (0, import_react.useMemo)(
302
313
  () => createStyles(theme, variant),
303
314
  [theme, variant]
@@ -397,7 +408,7 @@ function TextField({
397
408
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native3.View, { style: [styles.root, style], children: [
398
409
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native3.Pressable, { onPress: handleContainerPress, disabled: isDisabled, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native3.View, { style: containerStyle, children: [
399
410
  leadingIcon ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native3.View, { style: styles.leadingIcon, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
400
- import_MaterialCommunityIcons.default,
411
+ MaterialCommunityIcons,
401
412
  {
402
413
  name: leadingIcon,
403
414
  size: ICON_SIZE2,
@@ -446,7 +457,7 @@ function TextField({
446
457
  hitSlop: 12,
447
458
  style: styles.trailingIconPressable,
448
459
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native3.View, { style: styles.trailingIcon, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
449
- import_MaterialCommunityIcons.default,
460
+ MaterialCommunityIcons,
450
461
  {
451
462
  name: trailingIcon,
452
463
  size: ICON_SIZE2,
@@ -13,9 +13,9 @@ interface TypographyProps extends Omit<TextProps, 'children' | 'style'> {
13
13
  * @default 'bodyMedium'
14
14
  */
15
15
  variant?: TypographyVariant;
16
- /** Override the text color. Defaults to the theme's `onSurface` color. */
16
+ /** Override the text color. Takes priority over `style.color`. Defaults to the theme's `onSurface` color. */
17
17
  color?: string;
18
- /** Additional text styles merged after the theme typography styles. */
18
+ /** Additional text styles. Can override the default theme color via `style.color` when no `color` prop is set. */
19
19
  style?: StyleProp<TextStyle>;
20
20
  /**
21
21
  * Override the underlying text component (e.g. Animated.Text).
@@ -48,17 +48,26 @@ function Typography({
48
48
  }) {
49
49
  const theme = (0, import_core.useTheme)();
50
50
  const typographyStyle = theme.typography[variant];
51
- const colorStyle = (0, import_react.useMemo)(
52
- () => ({ color: color != null ? color : theme.colors.onSurface }),
53
- [color, theme.colors.onSurface]
54
- );
55
51
  const resolvedRole = accessibilityRole != null ? accessibilityRole : HEADING_VARIANTS.has(variant) ? "header" : void 0;
52
+ const lineHeightFix = (0, import_react.useMemo)(() => {
53
+ if (!style) return void 0;
54
+ const flat = import_react_native.StyleSheet.flatten(style);
55
+ if (!(flat == null ? void 0 : flat.fontSize) || flat.lineHeight) return void 0;
56
+ const ratio = typographyStyle.lineHeight / typographyStyle.fontSize;
57
+ return { lineHeight: Math.ceil(flat.fontSize * ratio) };
58
+ }, [style, typographyStyle.fontSize, typographyStyle.lineHeight]);
56
59
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
57
60
  Component,
58
61
  {
59
62
  ...textProps,
60
63
  accessibilityRole: resolvedRole,
61
- style: [typographyStyle, colorStyle, style],
64
+ style: [
65
+ { color: theme.colors.onSurface },
66
+ typographyStyle,
67
+ style,
68
+ lineHeightFix,
69
+ color != null ? { color } : void 0
70
+ ],
62
71
  children
63
72
  }
64
73
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlynative/components",
3
- "version": "0.1.0-alpha.0",
3
+ "version": "0.1.0-alpha.3",
4
4
  "description": "Material Design 3 UI components for React Native — Button, Card, Chip, TextField, and more.",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -117,7 +117,8 @@
117
117
  }
118
118
  },
119
119
  "publishConfig": {
120
- "access": "public"
120
+ "access": "public",
121
+ "provenance": true
121
122
  },
122
123
  "files": [
123
124
  "dist",
@@ -145,11 +146,16 @@
145
146
  },
146
147
  "peerDependencies": {
147
148
  "@expo/vector-icons": ">=14.0.0",
148
- "@onlynative/core": ">=0.1.0-alpha.0",
149
+ "@onlynative/core": ">=0.1.0-alpha.3",
149
150
  "react": ">=18.0.0",
150
151
  "react-native": ">=0.72.0",
151
152
  "react-native-safe-area-context": ">=4.0.0"
152
153
  },
154
+ "peerDependenciesMeta": {
155
+ "@expo/vector-icons": {
156
+ "optional": true
157
+ }
158
+ },
153
159
  "devDependencies": {
154
160
  "@react-native/babel-preset": "^0.81.5",
155
161
  "@onlynative/core": "workspace:*",
@@ -1,8 +1,8 @@
1
1
  import { StyleSheet } from 'react-native'
2
2
  import { defaultTopAppBarTokens } from '@onlynative/core'
3
- import type { Theme } from '@onlynative/core'
3
+ import type { MaterialTheme } from '@onlynative/core'
4
4
 
5
- export function createStyles(theme: Theme) {
5
+ export function createStyles(theme: MaterialTheme) {
6
6
  const topAppBar = theme.topAppBar ?? defaultTopAppBarTokens
7
7
 
8
8
  return StyleSheet.create({
@@ -1,4 +1,3 @@
1
- import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons'
2
1
  import { useMemo } from 'react'
3
2
  import { Platform, Pressable } from 'react-native'
4
3
  import { StyleSheet } from 'react-native'
@@ -6,6 +5,7 @@ import { Text } from 'react-native'
6
5
  import type { StyleProp, ViewStyle } from 'react-native'
7
6
  import { useTheme } from '@onlynative/core'
8
7
 
8
+ import { getMaterialCommunityIcons } from '../utils/icon'
9
9
  import { createStyles } from './styles'
10
10
  import type { ButtonProps } from './types'
11
11
 
@@ -75,6 +75,9 @@ export function Button({
75
75
  [theme, variant, hasLeading, hasTrailing, containerColor, contentColor],
76
76
  )
77
77
 
78
+ const MaterialCommunityIcons =
79
+ leadingIcon || trailingIcon ? getMaterialCommunityIcons() : null
80
+
78
81
  const resolvedIconColor = useMemo(() => {
79
82
  const base = StyleSheet.flatten([
80
83
  styles.label,
@@ -1,5 +1,5 @@
1
1
  import { StyleSheet } from 'react-native'
2
- import type { Theme } from '@onlynative/core'
2
+ import type { MaterialTheme } from '@onlynative/core'
3
3
 
4
4
  import type { ButtonVariant } from './types'
5
5
  import { alphaColor, blendColor } from '../utils/color'
@@ -17,7 +17,7 @@ interface VariantColors {
17
17
  disabledBorderColor: string
18
18
  }
19
19
 
20
- function getVariantColors(theme: Theme, variant: ButtonVariant): VariantColors {
20
+ function getVariantColors(theme: MaterialTheme, variant: ButtonVariant): VariantColors {
21
21
  const disabledContainerColor = alphaColor(theme.colors.onSurface, 0.12)
22
22
  const disabledLabelColor = alphaColor(theme.colors.onSurface, 0.38)
23
23
  const disabledOutlineColor = alphaColor(theme.colors.onSurface, 0.12)
@@ -129,7 +129,7 @@ function getVariantColors(theme: Theme, variant: ButtonVariant): VariantColors {
129
129
  }
130
130
 
131
131
  function getHorizontalPadding(
132
- theme: Theme,
132
+ theme: MaterialTheme,
133
133
  variant: ButtonVariant,
134
134
  hasLeadingIcon: boolean,
135
135
  hasTrailingIcon: boolean,
@@ -154,7 +154,7 @@ function getHorizontalPadding(
154
154
  }
155
155
 
156
156
  function applyColorOverrides(
157
- theme: Theme,
157
+ theme: MaterialTheme,
158
158
  colors: VariantColors,
159
159
  containerColor?: string,
160
160
  contentColor?: string,
@@ -209,7 +209,7 @@ function applyColorOverrides(
209
209
  }
210
210
 
211
211
  export function createStyles(
212
- theme: Theme,
212
+ theme: MaterialTheme,
213
213
  variant: ButtonVariant,
214
214
  hasLeadingIcon: boolean,
215
215
  hasTrailingIcon: boolean,
@@ -1,5 +1,5 @@
1
1
  import { StyleSheet } from 'react-native'
2
- import type { Theme } from '@onlynative/core'
2
+ import type { MaterialTheme } from '@onlynative/core'
3
3
 
4
4
  import type { CardVariant } from './types'
5
5
  import { alphaColor, blendColor } from '../utils/color'
@@ -15,7 +15,7 @@ interface VariantColors {
15
15
  disabledBorderColor: string
16
16
  }
17
17
 
18
- function getVariantColors(theme: Theme, variant: CardVariant): VariantColors {
18
+ function getVariantColors(theme: MaterialTheme, variant: CardVariant): VariantColors {
19
19
  const disabledContainerColor = alphaColor(theme.colors.onSurface, 0.12)
20
20
  const disabledOutlineColor = alphaColor(theme.colors.onSurface, 0.12)
21
21
 
@@ -78,7 +78,7 @@ function getVariantColors(theme: Theme, variant: CardVariant): VariantColors {
78
78
  }
79
79
 
80
80
  function applyColorOverrides(
81
- theme: Theme,
81
+ theme: MaterialTheme,
82
82
  colors: VariantColors,
83
83
  containerColor?: string,
84
84
  ): VariantColors {
@@ -103,7 +103,7 @@ function applyColorOverrides(
103
103
  }
104
104
 
105
105
  export function createStyles(
106
- theme: Theme,
106
+ theme: MaterialTheme,
107
107
  variant: CardVariant,
108
108
  containerColor?: string,
109
109
  ) {
@@ -1,9 +1,9 @@
1
- import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons'
2
1
  import { useMemo } from 'react'
3
2
  import { Platform, Pressable, StyleSheet, View } from 'react-native'
4
3
  import type { StyleProp, ViewStyle } from 'react-native'
5
4
  import { useTheme } from '@onlynative/core'
6
5
 
6
+ import { getMaterialCommunityIcons } from '../utils/icon'
7
7
  import { createStyles } from './styles'
8
8
  import type { CheckboxProps } from './types'
9
9
 
@@ -55,6 +55,10 @@ export function Checkbox({
55
55
  const isDisabled = Boolean(disabled)
56
56
  const isChecked = Boolean(value)
57
57
 
58
+ const MaterialCommunityIcons = isChecked
59
+ ? getMaterialCommunityIcons()
60
+ : null
61
+
58
62
  const theme = useTheme()
59
63
  const styles = useMemo(
60
64
  () => createStyles(theme, isChecked, containerColor, contentColor),
@@ -1,5 +1,5 @@
1
1
  import { StyleSheet } from 'react-native'
2
- import type { Theme } from '@onlynative/core'
2
+ import type { MaterialTheme } from '@onlynative/core'
3
3
 
4
4
  import { alphaColor, blendColor } from '../utils/color'
5
5
 
@@ -16,7 +16,7 @@ interface BoxColors {
16
16
  disabledIconColor: string
17
17
  }
18
18
 
19
- function getColors(theme: Theme, checked: boolean): BoxColors {
19
+ function getColors(theme: MaterialTheme, checked: boolean): BoxColors {
20
20
  const disabledOnSurface38 = alphaColor(theme.colors.onSurface, 0.38)
21
21
 
22
22
  if (checked) {
@@ -63,7 +63,7 @@ function getColors(theme: Theme, checked: boolean): BoxColors {
63
63
  }
64
64
 
65
65
  function applyColorOverrides(
66
- theme: Theme,
66
+ theme: MaterialTheme,
67
67
  colors: BoxColors,
68
68
  containerColor?: string,
69
69
  contentColor?: string,
@@ -96,7 +96,7 @@ function applyColorOverrides(
96
96
  }
97
97
 
98
98
  export function createStyles(
99
- theme: Theme,
99
+ theme: MaterialTheme,
100
100
  checked: boolean,
101
101
  containerColor?: string,
102
102
  contentColor?: string,
package/src/chip/Chip.tsx CHANGED
@@ -1,9 +1,9 @@
1
- import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons'
2
1
  import { useMemo } from 'react'
3
2
  import { Platform, Pressable, StyleSheet, Text, View } from 'react-native'
4
3
  import type { StyleProp, ViewStyle } from 'react-native'
5
4
  import { useTheme } from '@onlynative/core'
6
5
 
6
+ import { getMaterialCommunityIcons } from '../utils/icon'
7
7
  import { createStyles } from './styles'
8
8
  import type { ChipProps } from './types'
9
9
 
@@ -72,6 +72,12 @@ export function Chip({
72
72
  (variant === 'filter' && isSelected),
73
73
  )
74
74
 
75
+ const needsIcons =
76
+ Boolean(leadingIcon) || (variant === 'filter' && isSelected) || showCloseIcon
77
+ const MaterialCommunityIcons = needsIcons
78
+ ? getMaterialCommunityIcons()
79
+ : null
80
+
75
81
  const theme = useTheme()
76
82
  const styles = useMemo(
77
83
  () =>
@@ -1,5 +1,5 @@
1
1
  import { StyleSheet } from 'react-native'
2
- import type { Theme } from '@onlynative/core'
2
+ import type { MaterialTheme } from '@onlynative/core'
3
3
 
4
4
  import type { ChipVariant } from './types'
5
5
  import { alphaColor, blendColor } from '../utils/color'
@@ -18,7 +18,7 @@ interface VariantColors {
18
18
  }
19
19
 
20
20
  function getVariantColors(
21
- theme: Theme,
21
+ theme: MaterialTheme,
22
22
  variant: ChipVariant,
23
23
  elevated: boolean,
24
24
  selected: boolean,
@@ -106,7 +106,7 @@ function getVariantColors(
106
106
  }
107
107
 
108
108
  function applyColorOverrides(
109
- theme: Theme,
109
+ theme: MaterialTheme,
110
110
  colors: VariantColors,
111
111
  containerColor?: string,
112
112
  contentColor?: string,
@@ -161,7 +161,7 @@ function applyColorOverrides(
161
161
  }
162
162
 
163
163
  export function createStyles(
164
- theme: Theme,
164
+ theme: MaterialTheme,
165
165
  variant: ChipVariant,
166
166
  elevated: boolean,
167
167
  selected: boolean,
@@ -1,9 +1,9 @@
1
- import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons'
2
1
  import { useMemo } from 'react'
3
2
  import { Pressable } from 'react-native'
4
3
  import type { StyleProp, ViewStyle } from 'react-native'
5
4
  import { useTheme } from '@onlynative/core'
6
5
 
6
+ import { getMaterialCommunityIcons } from '../utils/icon'
7
7
  import { createStyles } from './styles'
8
8
  import type {
9
9
  IconButtonProps,
@@ -263,6 +263,7 @@ export function IconButton({
263
263
  accessibilityLabel,
264
264
  ...props
265
265
  }: IconButtonProps) {
266
+ const MaterialCommunityIcons = getMaterialCommunityIcons()
266
267
  const theme = useTheme()
267
268
  const styles = useMemo(() => createStyles(theme), [theme])
268
269
  const isDisabled = Boolean(disabled)
@@ -1,8 +1,8 @@
1
1
  import { StyleSheet } from 'react-native'
2
- import type { Theme } from '@onlynative/core'
2
+ import type { MaterialTheme } from '@onlynative/core'
3
3
  import { alphaColor, blendColor } from '../utils/color'
4
4
 
5
- export function createStyles(theme: Theme) {
5
+ export function createStyles(theme: MaterialTheme) {
6
6
  const disabledContainerColor = alphaColor(theme.colors.onSurface, 0.12)
7
7
  const disabledOutlineColor = alphaColor(theme.colors.onSurface, 0.12)
8
8
  const toggleUnselectedContainerColor = theme.colors.surfaceContainerHighest
@@ -1,8 +1,8 @@
1
- import type { Theme } from '@onlynative/core'
1
+ import type { MaterialTheme } from '@onlynative/core'
2
2
  import type { SpacingValue } from './types'
3
3
 
4
4
  export function resolveSpacing(
5
- spacing: Theme['spacing'],
5
+ spacing: MaterialTheme['spacing'],
6
6
  value: SpacingValue | undefined,
7
7
  ): number | undefined {
8
8
  if (value === undefined) return undefined
@@ -1,8 +1,8 @@
1
1
  import type { FlexAlignType, ViewProps } from 'react-native'
2
- import type { Theme } from '@onlynative/core'
2
+ import type { MaterialTheme } from '@onlynative/core'
3
3
 
4
4
  /** A theme spacing token name or a raw numeric value in dp. */
5
- export type SpacingValue = keyof Theme['spacing'] | number
5
+ export type SpacingValue = keyof MaterialTheme['spacing'] | number
6
6
 
7
7
  export interface BoxProps extends ViewProps {
8
8
  /** Padding on all sides */
@@ -1,5 +1,5 @@
1
1
  import { StyleSheet } from 'react-native'
2
- import type { Theme } from '@onlynative/core'
2
+ import type { MaterialTheme } from '@onlynative/core'
3
3
 
4
4
  import type { ListItemLines } from './types'
5
5
  import { alphaColor, blendColor } from '../utils/color'
@@ -13,7 +13,7 @@ const MIN_HEIGHT: Record<ListItemLines, number> = {
13
13
  3: 88,
14
14
  }
15
15
 
16
- export function createListStyles(theme: Theme) {
16
+ export function createListStyles(theme: MaterialTheme) {
17
17
  return StyleSheet.create({
18
18
  container: {
19
19
  paddingVertical: theme.spacing.sm,
@@ -27,7 +27,7 @@ interface ItemColors {
27
27
  pressedBackgroundColor: string
28
28
  }
29
29
 
30
- function getItemColors(theme: Theme, containerColor?: string): ItemColors {
30
+ function getItemColors(theme: MaterialTheme, containerColor?: string): ItemColors {
31
31
  const base = containerColor ?? 'transparent'
32
32
 
33
33
  if (containerColor) {
@@ -60,7 +60,7 @@ function getItemColors(theme: Theme, containerColor?: string): ItemColors {
60
60
  }
61
61
 
62
62
  export function createListItemStyles(
63
- theme: Theme,
63
+ theme: MaterialTheme,
64
64
  lines: ListItemLines,
65
65
  containerColor?: string,
66
66
  ) {
@@ -121,7 +121,7 @@ export function createListItemStyles(
121
121
  })
122
122
  }
123
123
 
124
- export function createDividerStyles(theme: Theme, inset: boolean) {
124
+ export function createDividerStyles(theme: MaterialTheme, inset: boolean) {
125
125
  return StyleSheet.create({
126
126
  divider: {
127
127
  height: 1,
@@ -1,7 +1,7 @@
1
1
  import { StyleSheet } from 'react-native'
2
- import type { Theme } from '@onlynative/core'
2
+ import type { MaterialTheme } from '@onlynative/core'
3
3
 
4
- import { alphaColor, blendColor } from '../utils/color'
4
+ import { alphaColor } from '../utils/color'
5
5
 
6
6
  interface RadioColors {
7
7
  borderColor: string
@@ -12,7 +12,7 @@ interface RadioColors {
12
12
  disabledDotColor: string
13
13
  }
14
14
 
15
- function getColors(theme: Theme, selected: boolean): RadioColors {
15
+ function getColors(theme: MaterialTheme, selected: boolean): RadioColors {
16
16
  const disabledOnSurface38 = alphaColor(theme.colors.onSurface, 0.38)
17
17
 
18
18
  if (selected) {
@@ -49,7 +49,7 @@ function getColors(theme: Theme, selected: boolean): RadioColors {
49
49
  }
50
50
 
51
51
  function applyColorOverrides(
52
- theme: Theme,
52
+ theme: MaterialTheme,
53
53
  colors: RadioColors,
54
54
  containerColor?: string,
55
55
  contentColor?: string,
@@ -79,7 +79,7 @@ function applyColorOverrides(
79
79
  }
80
80
 
81
81
  export function createStyles(
82
- theme: Theme,
82
+ theme: MaterialTheme,
83
83
  selected: boolean,
84
84
  containerColor?: string,
85
85
  contentColor?: string,
@@ -1,9 +1,9 @@
1
- import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons'
2
1
  import { useMemo } from 'react'
3
2
  import { Platform, Pressable, StyleSheet, View } from 'react-native'
4
3
  import type { StyleProp, ViewStyle } from 'react-native'
5
4
  import { useTheme } from '@onlynative/core'
6
5
 
6
+ import { getMaterialCommunityIcons } from '../utils/icon'
7
7
  import { createStyles } from './styles'
8
8
  import type { SwitchProps } from './types'
9
9
 
@@ -80,6 +80,9 @@ export function Switch({
80
80
  }
81
81
 
82
82
  const iconName = isSelected ? selectedIcon : unselectedIcon
83
+ const MaterialCommunityIcons = iconName
84
+ ? getMaterialCommunityIcons()
85
+ : null
83
86
  const iconSize = 16
84
87
 
85
88
  return (
@@ -1,5 +1,5 @@
1
1
  import { StyleSheet } from 'react-native'
2
- import type { Theme } from '@onlynative/core'
2
+ import type { MaterialTheme } from '@onlynative/core'
3
3
 
4
4
  import { alphaColor, blendColor } from '../utils/color'
5
5
 
@@ -17,7 +17,7 @@ interface TrackColors {
17
17
  disabledBorderWidth: number
18
18
  }
19
19
 
20
- function getColors(theme: Theme, selected: boolean): TrackColors {
20
+ function getColors(theme: MaterialTheme, selected: boolean): TrackColors {
21
21
  const disabledOnSurface12 = alphaColor(theme.colors.onSurface, 0.12)
22
22
  const disabledOnSurface38 = alphaColor(theme.colors.onSurface, 0.38)
23
23
 
@@ -69,7 +69,7 @@ function getColors(theme: Theme, selected: boolean): TrackColors {
69
69
  }
70
70
 
71
71
  function applyColorOverrides(
72
- theme: Theme,
72
+ theme: MaterialTheme,
73
73
  colors: TrackColors,
74
74
  containerColor?: string,
75
75
  contentColor?: string,
@@ -106,7 +106,7 @@ function applyColorOverrides(
106
106
  }
107
107
 
108
108
  export function createStyles(
109
- theme: Theme,
109
+ theme: MaterialTheme,
110
110
  selected: boolean,
111
111
  hasIcon: boolean,
112
112
  containerColor?: string,