> For the complete documentation index, see [llms.txt](https://wiki.nushackers.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.nushackers.org/orbital/react-native/handling-ui.md).

# Handling UI

Think of it as a tool that allows you to to create stuff with logic and UI. Since CS1101S (or any of the CS1010 variants) focuses mainly on logic, this might be the first time you are dealing with UI.

UI is generally handled with the JSX syntax in the previous section. For React Native, we have some basic out-of-the-box components that we can use.

## Common React Native Components

These components are enough to solve 90% of your needs.

* `View`: A container like `div`
* `ScrollView`: Like `View` but Scrollable
* `Text`: Displays texts
* `Button`: Supports touches
* `TouchableOpacity`: Like `Button` but can encapsulate Button
* `TextInput`: Supports inputting texts
* `Image`: Display images

You can read up on other components [here](https://reactnative.dev/docs/components-and-apis).

## Organizing Components

Components can be organised using [flex box](https://css-tricks.com/snippets/css/a-guide-to-flexbox/). Understanding the 4 concepts below can meet 90% of your needs. Later on we will try to create the mockup for NUS NextBUS using these concepts alone.

### **Flex direction**

<figure><img src="/files/zDD8aenrKaPRbfByrhiU" alt=""><figcaption><p>flex direction</p></figcaption></figure>

* `row`: organise components horizontally
* `column`: organise components vertically

### **Justify content**

<figure><img src="/files/tZ3XMvyidVy1caZZydQZ" alt=""><figcaption><p>justify content</p></figcaption></figure>

* `space-between`: Spread out components evenly. First component at the left end, last component at the end.
* `center`: Components are centered.

### Styling UI components

You can style components using the `StyleSheet`:

```jsx
import { StyleSheet, Text, View } from 'react-native';

const App = () => (
  <View style={styles.container}>
    <Text style={styles.title}>React Native</Text>
  </View>
);

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#eaeaea',
  },
  title: {
    marginTop: 16,
    backgroundColor: '#61dafb',
    color: '#20232a',
    fontSize: 30,
    fontWeight: 'bold',
  },
});
```

Alternatively, you can style components using CSS libraries such as [Tailwind](https://tailwindcss.com/). There are different paradigms to approach styling components but the general idea is the same - they all uses concepts from CSS. You can visit the [CSS](/orbital/readme-1/css.md) section in the wiki for more info!

{% hint style="info" %}
You can set the background colour to black to visualise the space that the component takes up.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://wiki.nushackers.org/orbital/react-native/handling-ui.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
