React NativeScript

React NativeScript

  • Docs

›ELEMENTS: COMPONENTS

INTRODUCTION

  • Introduction

GETTING STARTED

  • Quick Start
  • Environment Setup
  • Using React Devtools

CORE CONCEPTS

  • Native Access
  • Navigation
  • Node Roles
  • Modals
  • Plugins
  • Styling

SAMPLES

  • Apps

ELEMENTS: LAYOUT

  • AbsoluteLayout
  • DockLayout
  • FlexboxLayout
  • GridLayout
  • StackLayout
  • WrapLayout

ELEMENTS: COMPONENTS

  • ActivityIndicator
  • ActionBar
  • ActionItem
  • Button
  • DatePicker
  • Frame
  • HtmlView
  • Image
  • Label
  • ListView
  • ListPicker
  • NavigationButton
  • Page
  • Placeholder
  • Progress
  • ScrollView
  • SearchBar
  • SegmentedBar
  • Slider
  • Switch
  • TabView
  • TabViewItem
  • TextField
  • TextView
  • TimePicker
  • WebView

LICENCES

  • Licences
Edit

ActionBar

<actionBar> is a UI component that provides a toolbar at the top of the activity window.

This component is the NativeScript abstraction for the Android app bar and the iOS navigation bar.

See also:

  • Official top-level documentation
  • Detailed API specification
  • <actionItem>
  • <navigationButton>

Introduction to Node Roles

ActionBars are a complex component that can contain child components serving different roles (e.g. navigation button, title view, or action item). React NativeScript provides a nodeRole property so that you can make it explicit what role each given child serves.

Take care not to miss the nodeRole property that we set in the following examples, to see which children (and grandchildren) require which roles.

See: Node Roles

Using a title

import * as React from "react";

<actionBar title="MyApp" />

Using a custom title view

import * as React from "react";

<actionBar>
  <stackLayout nodeRole={"titleView"} orientation="horizontal">
    <image src="res://icon" width={40} height={40} verticalAlignment="center" />
    <label text="NativeScript" fontSize={24} verticalAlignment="center" />
  </stackLayout>
</actionBar>

Removing the border

By default, a border is drawn at the bottom of the <actionBar>. In addition to the border, on iOS devices a translucency filter is also applied over the <actionBar>.

To remove this styling from your app, you can set the flat property to true.

import * as React from "react";

<actionBar title="My App" flat={true} />

Adding buttons

import * as React from "react";

<actionBar>
  <label nodeRole={"titleView"}>Hello Title View</label>
  <actionItem nodeRole={"actionItems"}>
    <button nodeRole={"actionView"}>One</button>
  </actionItem>
  <actionItem nodeRole={"actionItems"}>
    <button nodeRole={"actionView"}>Two</button>
  </actionItem>
  <actionItem nodeRole={"actionItems"}>
    <button nodeRole={"actionView"}>Three</button>
  </actionItem>
</actionBar>

Setting an app icon for Android

import * as React from "react";

<actionBar title="My App" android={{ icon: "res://icon", iconVisibility: "always" }} />

Props

NameTypeDescription
titlestringSets the title shown in the bar.
flatbooleanRemoves the border on Android and the translucency on iOS. Default value is false.

Native component

AndroidiOS
android.widget.ToolbarUINavigationBar
Last updated by Jamie Birch
← ActivityIndicatorActionItem →
  • Props
  • Native component
React NativeScript
Docs
Getting StartedUI Components Reference
Community
Stack OverflowChat on Slack in #reactTwitter
More
GitHub – React NativeScriptGitHub – Docs Site
Copyright © 2021 Jamie Birch