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 — Customizing Components | NativeBase | Universal Components for React and React Native

Customizing Components | 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.
Customizing Components
Theme customisation is at the heart of NativeBase. Using NativeBase's extendTheme function, we can customise components.
Components can be customised by overriding baseStyle/defaultProps or adding a new variant.
Let's customise a Button component to include rounded borders and red colorScheme.
Basic
Copy
import React from 'react';
import { NativeBaseProvider, extendTheme } from 'native-base';
export default function () {
const theme = extendTheme({
components: {
Button: {
// Can simply pass default props to change default behaviour of components.
baseStyle: {
rounded: 'md',
},
defaultProps: {
colorScheme: 'red',
},
},
Heading: {
// Can pass also function, giving you access theming tools
baseStyle: ({ colorMode }) => {
return {
color: colorMode === 'dark' ? 'red.300' : 'blue.300',
fontWeight: 'normal',
};
},
},
},
});
return (
<NativeBaseProvider theme={theme}>{/* components */}</NativeBaseProvider>
);
}
As shown above, we can customize components by passing the components object with the key being the name of the component. Whereas you set defaultProps or baseStyle to customize the components.
Difference between baseStyle and defaultProps
Base Style
As the name suggests, it's used to define the base style of a component.
Base style can be a function or a plain object. Use function if you want to get access to defaultProps, current colorMode (light/dark) and theme object.
Take a look at an
example here
.
Default Props
Default props can be used to initialize props of a component.
For e.g. You have a Button component and it has 2 variants. i.e. outline, solid.
Take a look at an
example here
.
Copy
<Button variant="ghost">
<Button variant="outline">
// What variant should it pick if it's not passed?
<Button />
When variant in defaultProps is solid the above button will use solid variant.
Customizing Base Style
You can specify the base style of the component and use it across project.
Playground
function Example() {
const theme = extendTheme({
components: {
Text: {
baseStyle: {
color: 'emerald.400'
},
defaultProps: {
size: 'lg'
},
sizes: {
xl: {
fontSize: '64px'
},
lg: {
fontSize: '32px'
},
md: {
fontSize: '16px'
},
sm: {
fontSize: '12px'
}
}
}
}
});
return <NativeBaseProvider theme={theme}>
<Center flex={1}>
<Text>NativeBase</Text>
</Center>
</NativeBaseProvider>;
}
Adding Variants
You can also add the variants to the components and use it across project.
Playground
const Example = () => {
const theme = extendTheme({
components: {
Button: {
variants: {
rounded: ({
colorScheme
}) => {
return {
bg: `${colorScheme}.500`,
rounded: "full"
};
}
}
}
}
});
return <NativeBaseProvider theme={theme}>
<Center flex={1}>
<VStack space={2}>
<Button colorScheme="emerald">Default Button</Button>
<Button colorScheme="emerald" variant="rounded">
Rounded Button
</Button>
</VStack>
</Center>
</NativeBaseProvider>;
};

NativeBase ships with default styles for each components.
You can find it here
.
Previous
Customizing Fonts
Next
Making components dark mode compatible
Quick Nav
Basic
Difference between baseStyle and defaultProps
Base Style
Default Props
Customizing Base Style
Adding Variants
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.