28
loading...
This website collects cookies to deliver better user experience
import React from "react"
import { View, Text } from "react-native"
import { apply } from "./OsmiProvider"
const App = () => {
return (
<View style={apply("flex items-center justify-center bg-white")}>
<Text style={apply("text-2xl font-bold text-center")}>Hello World</Text>
</View>
)
}
Button.js
import React, { memo } from "react"
import { TouchableOpacity, Text } from "react-native"
// styles
import styles from "./ButtonStyle"
const Button = props => {
const { buttonStyle, labelStyle, title } = props
return (
<TouchableOpacity activeOpacity={0.8} {...props} style={[styles.container, buttonStyle]}>
{props?.children ?? (
<Text style={[styles.label, labelStyle]}>{title}</Text>
)}
</TouchableOpacity>
)
}
export default memo(Button)
ButtonStyle.js
import { connect } from "./OsmiProvider"
export default connect({
container: "py-2 px-5 bg-blue-500 rounded-md",
label: "text-white text-base font-bold"
})
CustomTheme.js
export default {
colors: {
// custom colors
},
spacing: {
// custom spacing
},
border: {
width: {
// border width
},
radius: {
// border radius
}
},
font: {
family: {
// font family
},
size: {
// font size
}
}
}
light
, dark
, or use system appearance
based on user device.dark:
to your style. Example:apply("flex bg-white dark:bg-gray-900")
bg-white
on light mode, and bg-gray-900
on dark mode. Next step, step if you want add switch theme button in your app, the whole code will be like this:import React, { useState } from "react"
import { TouchableOpacity, View, Text } from "react-native"
import { apply } from "./OsmiProvider"
import { appearanceHook } from "osmicsx"
const Settings = props => {
const [currentTheme, setCurrentTheme] = useState(appearanceHook.theme)
const switchTheme = (value) => {
appearanceHook.switch(value)
setCurrentTheme(value)
}
return (
<View style={apply("flex bg-white dark:bg-gray-900 items-center justify-center")}>
<Text style={apply("text-gray-900 dark:text-white text-center text-2xl font-bold")} onPress={() => switchTheme("light")}>Switch to Light</Text>
<Text style={apply("text-gray-900 dark:text-white text-center text-2xl font-bold")} onPress={() => switchTheme("dark")}>Switch to Dark</Text>
</View>
)
}
.switch()
method. light
, dark
, and system
. For more details check Documentation