重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
react-native-unistyles-v3 by jpudysz/react-native-unistyles
npx skills add https://github.com/jpudysz/react-native-unistyles --skill react-native-unistyles-v3您正在协助使用 React Native Unistyles v3 进行样式设置。v3 是一个零重新渲染的样式库,具有 C++ 核心(Nitro Modules)和一个在构建时处理 StyleSheets 的 Babel 插件。它用一套响应式、主题感知、自适应的系统取代了 React Native 的 StyleSheet。
react-native-nitro-modules(原生桥接依赖)react-native-edge-to-edge(Android 边到边安全区域所需)import { StyleSheet } from 'react-native-unistyles'
// 1. 静态对象,兼容 React Native 的 StyleSheet.create
const styles = StyleSheet.create({
container: { flex: 1, padding: 16 }
})
// 2. 主题函数(响应主题变化,零重新渲染)
const styles = StyleSheet.create(theme => ({
container: { backgroundColor: theme.colors.background }
}))
// 3. 主题 + 迷你运行时函数(响应主题和设备状态)
const styles = StyleSheet.create((theme, rt) => ({
container: {
backgroundColor: theme.colors.background,
paddingTop: rt.insets.top,
width: rt.screen.width > 768 ? 500 : rt.screen.width - 32
}
}))
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
StyleSheet.configure({
themes: { light: lightTheme, dark: darkTheme },
breakpoints: { xs: 0, sm: 576, md: 768, lg: 992, xl: 1200 },
settings: {
initialTheme: 'light', // 或:() => storage.getString('theme') ?? 'light'
// adaptiveThemes: true, // 基于操作系统自动切换浅色/深色主题(与 initialTheme 互斥)
// CSSVars: true, // 在 Web 上使用 CSS 自定义属性
// nativeBreakpointsMode: 'pixels' | 'points'
}
})
const styles = StyleSheet.create(theme => ({
button: {
variants: {
size: {
small: { padding: 4 },
medium: { padding: 8 },
large: { padding: 16 },
},
color: {
primary: { backgroundColor: theme.colors.primary },
secondary: { backgroundColor: theme.colors.secondary },
}
},
compoundVariants: [
{ size: 'large', color: 'primary', styles: { borderWidth: 2 } }
],
}
}))
// 在组件中 — 在访问样式前调用 useVariants
styles.useVariants({ size: 'large', color: 'primary' })
return <View style={styles.button} />
import { withUnistyles } from 'react-native-unistyles'
import { Button } from 'some-library'
const UniButton = withUnistyles(Button, (theme, rt) => ({
color: theme.colors.primary,
size: rt.screen.width > 400 ? 'large' : 'small'
}))
// 用法:<UniButton title="Press me" />
{...styles.x} 会破坏 C++ 代理绑定。始终使用数组语法:[styles.x, styles.y] 或 [styles.x, { marginTop: 10 }]StyleSheet.create。重新导出会破坏检测。['react-native-unistyles/plugin', { root: 'src' }]。没有它,样式将不具备响应性。react-native-unistyles 导入 StyleSheet — 它填充了所有 RN StyleSheet API(hairlineWidth、compose、flatten、absoluteFill)。替换所有 import { StyleSheet } from 'react-native'。styles.useVariants() 必须在访问依赖变体的样式之前调用 — 将其视为 React 钩子(组件顶部)。StyleSheet.create(theme => ...) 而非 useUnistyles() — 主题函数实现零重新渲染;useUnistyles() 会在每次主题/运行时变化时触发重新渲染。StyleSheet.configure() 必须在任何 StyleSheet.create() 之前调用 — 通常在应用的入口点,在任何组件渲染之前。需要在样式中使用主题/运行时吗?
├─ 是 → StyleSheet.create((theme, rt) => ...) [零重新渲染]
└─ 否 → StyleSheet.create({ ... }) [静态样式]
需要将主题值作为非样式属性吗?
├─ 是 → withUnistyles(Component, (theme, rt) => ({ propName: theme.value }))
└─ 否 → 直接通过 style 属性传递 Unistyles 样式
需要在组件逻辑(不仅仅是样式)中使用主题/运行时吗?
├─ 是 → useUnistyles() 钩子 [会导致重新渲染]
└─ 否 → 使用带主题函数的 StyleSheet.create
组件是否接受 `style` 属性?
├─ 是 → 直接传递 Unistyles 样式(Babel 会自动处理标准 RN 视图)
│ 如果是自定义原生视图 → 添加到 Babel 配置的 autoProcessPaths 中
├─ 否 → 它是否接受源自主题的属性(颜色、尺寸等)?
│ ├─ 是 → withUnistyles(Component, (theme, rt) => ({ prop: theme.value }))
│ └─ 否 → 回退使用 useUnistyles()
└─ 来自 node_modules 的组件未被处理?
→ 将其路径添加到 Babel 插件配置的 autoProcessPaths 或 autoProcessImports 中
每周安装量
66
代码仓库
GitHub 星标数
2.8K
首次出现
2026年3月10日
安全审计
安装于
kimi-cli66
github-copilot66
gemini-cli66
codex66
amp66
cline66
You are assisting with React Native Unistyles v3 styling. v3 is a zero-re-render styling library with a C++ core (Nitro Modules) and Babel plugin that processes StyleSheets at build time. It replaces React Native's StyleSheet with a reactive, theme-aware, responsive system.
react-native-nitro-modules (native bridge dependency)react-native-edge-to-edge (required for Android edge-to-edge insets)import { StyleSheet } from 'react-native-unistyles'
// 1. Static object compatible with React Native StyleSheet.create
const styles = StyleSheet.create({
container: { flex: 1, padding: 16 }
})
// 2. Theme function (reactive to theme changes, zero re-renders)
const styles = StyleSheet.create(theme => ({
container: { backgroundColor: theme.colors.background }
}))
// 3. Theme + miniRuntime function (reactive to theme AND device state)
const styles = StyleSheet.create((theme, rt) => ({
container: {
backgroundColor: theme.colors.background,
paddingTop: rt.insets.top,
width: rt.screen.width > 768 ? 500 : rt.screen.width - 32
}
}))
StyleSheet.configure({
themes: { light: lightTheme, dark: darkTheme },
breakpoints: { xs: 0, sm: 576, md: 768, lg: 992, xl: 1200 },
settings: {
initialTheme: 'light', // or: () => storage.getString('theme') ?? 'light'
// adaptiveThemes: true, // auto-switch light/dark based on OS (mutually exclusive with initialTheme)
// CSSVars: true, // use CSS custom properties on web
// nativeBreakpointsMode: 'pixels' | 'points'
}
})
const styles = StyleSheet.create(theme => ({
button: {
variants: {
size: {
small: { padding: 4 },
medium: { padding: 8 },
large: { padding: 16 },
},
color: {
primary: { backgroundColor: theme.colors.primary },
secondary: { backgroundColor: theme.colors.secondary },
}
},
compoundVariants: [
{ size: 'large', color: 'primary', styles: { borderWidth: 2 } }
],
}
}))
// In component — call useVariants BEFORE accessing styles
styles.useVariants({ size: 'large', color: 'primary' })
return <View style={styles.button} />
import { withUnistyles } from 'react-native-unistyles'
import { Button } from 'some-library'
const UniButton = withUnistyles(Button, (theme, rt) => ({
color: theme.colors.primary,
size: rt.screen.width > 400 ? 'large' : 'small'
}))
// Usage: <UniButton title="Press me" />
{...styles.x} breaks C++ proxy binding. ALWAYS use array syntax: [styles.x, styles.y] or [styles.x, { marginTop: 10 }]StyleSheet.create by import source. Re-exporting breaks detection.['react-native-unistyles/plugin', { root: 'src' }] to babel.config.js. Without it, styles won't be reactive.react-native-unistyles only — it polyfills all RN StyleSheet APIs (hairlineWidth, compose, , ). Replace all .Need theme/runtime in styles?
├─ YES → StyleSheet.create((theme, rt) => ...) [zero re-renders]
└─ NO → StyleSheet.create({ ... }) [static styles]
Need theme values as non-style props?
├─ YES → withUnistyles(Component, (theme, rt) => ({ propName: theme.value }))
└─ NO → Pass Unistyles styles via style prop directly
Need theme/runtime in component logic (not just styles)?
├─ YES → useUnistyles() hook [causes re-renders]
└─ NO → Use StyleSheet.create with theme function
Does the component accept a `style` prop?
├─ YES → Pass Unistyles styles directly (Babel auto-processes standard RN views)
│ If it's a custom native view → add to autoProcessPaths in Babel config
├─ NO → Does it accept theme-derived props (color, size, etc.)?
│ ├─ YES → withUnistyles(Component, (theme, rt) => ({ prop: theme.value }))
│ └─ NO → useUnistyles() as fallback
└─ Component from node_modules not processed?
→ Add its path to autoProcessPaths or autoProcessImports in Babel plugin config
Weekly Installs
66
Repository
GitHub Stars
2.8K
First Seen
Mar 10, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
kimi-cli66
github-copilot66
gemini-cli66
codex66
amp66
cline66
GSAP React 动画库使用指南:useGSAP Hook 与最佳实践
3,500 周安装
flattenabsoluteFillimport { StyleSheet } from 'react-native'styles.useVariants() must be called before accessing variant-dependent styles — treat it like a React hook (top of component).StyleSheet.create(theme => ...) over useUnistyles() — theme functions cause zero re-renders; useUnistyles() re-renders on every theme/runtime change.StyleSheet.configure() must be called before any StyleSheet.create() — typically in your app entry point, before any component renders.