GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing docs.nativebase.io — Making Components Dark Mode Compatible | NativeBase | Universal Components for React and React Native

Making Components Dark Mode Compatible | NativeBase | Universal Components for React and React Native

NativeBase
3.4.x
🎉 Prompt to React Native UI
→
Search
⌘
K
Hire us
NativeBase
Introduction
Getting Started
Installation
Setup NativeBase Provider
Migration
Upgrading to v3
Upgrading to 3.2.0 from 3.x
Upgrading to 3.4.0 from 3.3.x
Components Migration
ActionSheet
Badge
Button
Card
Checkbox
DatePicker
DeckSwiper
Drawer
FABs
FooterTab
Form
Header
Icon
Layout
Picker
Radio Button
Searchbar
Segment
Spinner
SwipeList
Tabs
Thumbnail
Toast
Typography
Resources
Contribution
Creating a Universal App with NativeBase and Solito
Core Concepts
Utility First
Utility Props Specificity
Design Tokens
Pseudo Props: Overview
Pseudo Props: Dos & Don'ts
Internal Pseudo Props
Responsive
Features
Utility Props
Color mode (Dark Mode)
NativeBase Factory
SafeAreaView Props
Strict Mode
Accessibility
Theme
Default Theme
Customizing Theme
Customizing Fonts
Customizing Components
Making components dark mode compatible
Breakpoints
Using Theme
TypeScript
Layout
AspectRatio
Box
Center
Container
Flex
HStack / Row
Stack
VStack / Column
ZStack
Forms
Button
Pressable
Checkbox
FormControl
IconButton
Input
Link
Radio
Select
Slider
Switch
TextArea
Data Display
Badge
Divider
Feedback
Alert
Progress
Skeleton
Spinner
Toast
Typography
Text
Heading
Overlay
AlertDialog
Menu
Modal
Popover
Tooltip
Disclosure
ActionSheet
Media and Icons
Avatar
Icon
Image
Transition
PresenceTransition
Slide
Stagger
Others
Fab
Hidden
ReactNative Components
ScrollView
View
KeyboardAvoidingView
StatusBar
FlatList
SectionList
Hooks
useDisclose
useBreakpointValue
useClipboard
useMediaQuery
useTheme
useToken
useColorMode
useColorModeValue
useContrastText
useAccessibleColors
Examples
Todo-List
Kitchen Sink
Recipes
Designs
AppBar
Card
Drawer Navigation
Tab View
Swipe List
Forms
Form with Validation
Login/Signup Forms
SearchBar
Layout
App Drawer
Footer
More
Changelog
Testing
FAQ's
More Props
If you are starting a new project, please try gluestack-ui for better performance and new design.
Making Components Dark Mode Compatible
By default, most of NativeBase's components are dark mode compatible. In some scenario, you might need to make your component respond to color mode. There are 2 ways to achieve this:
By updating component's theme
By using useColorModeValue
1. By updating component's theme
In this approach we use NativeBase's extendTheme function to customise the components and then use _light and _dark props to make the component dark mode compatible.
Note: Changes on the theme will be reflected on the entire application.
Copy
import React from 'react';
import { NativeBaseProvider } from 'native-base';
import { extendTheme } from 'native-base';
import { Content } from './Content';
export default function () {
const theme = extendTheme({
components: {
Heading: {
baseStyle: (props: any) => {
return {
_light: { color: 'red.300' },
_dark: { color: 'blue.300' },
};
},
},
},
});
return (
<NativeBaseProvider theme={theme}>
<Content />
</NativeBaseProvider>
);
}
In the above example, the Heading component's color property will now respond to change in color, namely in light mode it will be red (red.300) colored and in dark mode it will be blue (blue.300) colored.
2. By using useColorModeValue
In this approach we use NativeBase's useColorModeValue hook and update specific props instead of updating the entire theme.
Note: Changes on the theme will be reflected on the entire application.
Copy
import React from 'react';
import { useColorModeValue, Button } from 'native-base';
export default function () {
const colorScheme = useColorModeValue('teal', 'amber');
const variant = useColorModeValue('solid', 'outline');
return (
<Button colorScheme={colorScheme} variant={variant}>
Sample
</Button>
);
}
In the above example, you'll get a solid teal Button in light mode whereas an outline amber Button in dark mode. You can get creative and make other properties respond to the color mode as well.
3. By using _light and _dark props
In this approach we pass the required props inside _light and _dark based on the requirement.
Copy
import React from 'react';
import { Button } from 'native-base';
export default function () {
return (
<Button
_light={{ bg: 'teal', _text: { color: 'white' } }}
_dark={{ bg: 'amber' }}
>
Sample
</Button>
);
}
In the above example, you'll get a teal Button in light mode whereas an amber Button in dark mode. You can get creative and make other properties respond to the color mode as well.
Previous
Customizing Components
Next
Breakpoints
Quick Nav
1. By updating component's theme
2. By using useColorModeValue
3. By using _light and _dark props
MadeWithNativeBase
gluestack-ui
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.