import { View } from '@uhg-abyss/mobile';Usage
The View component is one of the fundamental building blocks of a user interface. It functions as a
container that supports layout, styling, and interaction handling. The component serves as a versatile
wrapper for organizing and displaying other components within a user interface.
While it extends the core View component present in React Native, the View component in Abyss Mobile
allows using tokens directly in the style prop. This feature enables developers to use the design tokens
defined in the theme to style a component.
This example creates a View that wraps two boxes with color and a text component in a row with padding. Notice the use of design tokens in the style prop.
Best Practices
- Use for Layout: Utilize the
Viewcomponent to create layouts and organize components within a user interface. For text context, consider using the Text component. - Avoid Excessive Nesting: Limit the number of nested
Viewcomponents to maintain a clean and efficient layout. - Use Tokens: Leverage design tokens in the style prop to ensure consistency and maintainability in styling.
- Accessibility: Ensure that the content within the
Viewcomponent is accessible to all users by providing appropriate labels and descriptions where necessary.
Performance Considerations
To maximize performance, be mindful of:
- Shallow component trees: Minimize nesting
Viewcomponents to reduce the complexity of the component tree. - Avoid unnecessary re-renders: Use
React.memoor similar optimization when rendering complex or frequently changing layouts.
View Classes
| Class Name | Description |
|---|---|
| abyss-view-root | View root element |
View Props
| Prop Name | Type | Default | Description |
|---|---|---|---|
| style | Abyss.Style<"View"> | - | Object or array of objects defining the style of the View component with design tokens. |