Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BottomTabBarRouter<Ttarget>

It creates BottomTabBarController and manages its behavours and routes.

example
import { BottommTabBarRouter, Route } from '@smartface/router';
import Image from '@smartface/native/ui/image';
import Color from '@smartface/native/ui/color';

var router = Router.of({
path: "/",
routes: [
BottomTabBarRouter.of(
path: '/tabs',
tabbarParams: () => ({
itemColor: {normal: Color.BLACK, selected: Color.BLUE},
backgroundColor: Color.BLUE,
}),
tabbarItems: [
{ title: "Page1", icon: Image.createFromFile("images://icon1.png") },
{ title: "Page2", icon: Image.createFromFile("images://icon2.png") },
],
routes: [
Route.of({
routeDidEnter: (router, route) => {
},
routeDidExit: (router, route) => {
},
path: "/tabs/page1",
build((router, route) => {
const Page1 = require('/pages/Page1');
return new Page1(route.getState().routeData, router);
})
}),
Route.of({
path: "/tabs/page2",
build((router, route) => {
const Page2 = require('/pages/Page2');
return new Page2(route.getState().routeData, router);
});
});
]
)]
})
since

1.0.0

Type parameters

  • Ttarget = Page

Hierarchy

  • NativeRouterBase<Ttarget>
    • BottomTabBarRouter

Index

Methods

Static of

setState

  • setState(state: Partial<RouteState<any>>): void
  • Merges specified state to current route state

    since

    1.0.0

    Parameters

    • state: Partial<RouteState<any>>

    Returns void

Static getGlobalRouter

  • getGlobalRouter(): HistoryController

Static getHistoryStack

  • getHistoryStack(): any[]

Static getLastHistory

  • getLastHistory(): any

Static getlocationHistoryByIndex

  • getlocationHistoryByIndex(index: number): any
  • Parameters

    • index: number

    Returns any

Static getHistoryByIndex

  • getHistoryByIndex(index: number): any

Static createBlocker

  • createBlocker(fn: Function): (router: Router<unknown>, path: null | string, routeData: null | object, action: HistoryActionType, doneFn: Function) => void
  • Parameters

    • fn: Function

    Returns (router: Router<unknown>, path: null | string, routeData: null | object, action: HistoryActionType, doneFn: Function) => void

      • (router: Router<unknown>, path: null | string, routeData: null | object, action: HistoryActionType, doneFn: Function): void
      • Parameters

        • router: Router<unknown>
        • path: null | string
        • routeData: null | object
        • action: HistoryActionType
        • doneFn: Function

        Returns void

Static getActiveRouter

  • getActiveRouter(): null | Router<unknown>

initializeRenderer

  • initializeRenderer(): void

initialize

  • initialize(parentHistory: HistoryController, onHistoryChange: OnHistoryChange<any>, pushHomes: (path: string) => void): void
  • Parameters

    • parentHistory: HistoryController
    • onHistoryChange: OnHistoryChange<any>
    • pushHomes: (path: string) => void
        • (path: string): void
        • Parameters

          • path: string

          Returns void

    Returns void

canGoBack

  • canGoBack(n: number): undefined | boolean

dispose

  • dispose(): void

push

renderMatches

  • renderMatches(matches: MatchReturn, location: Location, action: HistoryActionType, target: Router<unknown>, fromRouter: boolean): void
  • override

    Parameters

    • matches: MatchReturn
    • location: Location
    • action: HistoryActionType
    • target: Router<unknown>
    • fromRouter: boolean

    Returns void

setHeaderbarProps

  • setHeaderbarProps(props: IHeaderBar): void

getState

  • getState(): RouteState<any>
  • Returns Route's current state

    since

    1.0.0

    Returns RouteState<any>

toJSON

  • toJSON(): { type: string; match: any; routeData: any; routingState: undefined | object; path: string; routes: Route<unknown>[]; state: RouteState<any> & { view: any } }
  • Simple Object representation of the route

    since

    1.0.0

    Returns { type: string; match: any; routeData: any; routingState: undefined | object; path: string; routes: Route<unknown>[]; state: RouteState<any> & { view: any } }

    • type: string
    • match: any
    • routeData: any
    • routingState: undefined | object
    • path: string
    • routes: Route<unknown>[]
    • state: RouteState<any> & { view: any }

toString

  • toString(): string
  • String representation of the route

    since

    1.0.0

    Returns string

setUrl

  • setUrl(url: string): void

clearUrl

  • clearUrl(): void

clearDirty

  • clearDirty(): void

getUrl

  • getUrl(): null | string

getRedirectto

  • getRedirectto(): undefined | string | (() => string)
  • Returns redirection path

    since

    1.0.0

    Returns undefined | string | (() => string)

build

  • build(router: Router<any>): any
  • Builds a route's view. This method is called whenever router is routing into that path. There are some exceptions:

    • going into a tab, which the tab is created before
    • for iOS, goingBack via gesture or headerBar back
    since

    1.0.0

    Parameters

    • router: Router<any>

      Not the root router, the router which the route belongs to.

    Returns any

    view = null - If the route has been built once, the previous view (page) is given. Otherwise it is null. If view is not null, returning the view back makes it singleton.

hasPath

  • hasPath(): boolean
  • If Route has a path or not

    since

    1.0.0

    Returns boolean

matchPath

  • matchPath(url: string): undefined | null | string | { path: string; url: any; isExact: boolean; params: any }
  • Checks if the specified url match to the route path

    Parameters

    • url: string

    Returns undefined | null | string | { path: string; url: any; isExact: boolean; params: any }

getUrlPath

  • getUrlPath(): string
  • Returns route path as string

    since

    1.0.0

    Returns string

getPath

  • getPath(): RoutePath
  • Clones route's path and returns

    since

    1.0.0

    Returns RoutePath

pushHomeRouteBefore

  • pushHomeRouteBefore(path: string): void

findChild

  • findChild(fn: (value: Route<unknown> | Router<unknown>, index: number, obj: (Route<unknown> | Router<unknown>)[]) => unknown): undefined | Route<unknown>
  • Finds and returns child Route or undefined

    since

    1.4.1

    Parameters

    • fn: (value: Route<unknown> | Router<unknown>, index: number, obj: (Route<unknown> | Router<unknown>)[]) => unknown
        • Parameters

          Returns unknown

    Returns undefined | Route<unknown>

historyPreventDefault

  • historyPreventDefault(): void

pushAndBack

  • pushAndBack(url: string, routeData: any): void
  • Parameters

    • url: string
    • routeData: any

    Returns void

hasHome

  • hasHome(): boolean

getCurrentUrl

  • getCurrentUrl(): undefined | string
  • Return current active url

    since

    1.0.0

    Returns undefined | string

listen

  • listen(fn: HistoryListenHandler): () => boolean
  • Adds eventlisteners to listen history changes

    example
    const unlisten = router.listen((location, action) => {
    console.log(`new route location: ${location.url} action : ${action}`);
    });
    since

    1.0.0

    Parameters

    • fn: HistoryListenHandler

    Returns () => boolean

      • (): boolean
      • Returns boolean

addRouteBlocker

  • addRouteBlocker(fn: RouteBlockHandler): () => void
  • Adds route block handler to history. When history is changed in anywhere then the handler intercepts before history is changed.

    example
    const unload = router.addRouteBlocker((path, routeData, action, ok) => {
    alert({
    message: "Would you like to answer?",
    title: "Question", //optional
    buttons: [{
    text: "Yes",
    type: AlertView.Android.ButtonType.POSITIVE,
    onClick: function() {
    ok(true);
    }
    },
    {
    text: "No",
    type: AlertView.Android.ButtonType.NEGATIVE,
    onClick: function() {
    ok(false);
    }
    }
    ]
    });
    });
    since

    1.0.0

    Parameters

    • fn: RouteBlockHandler

    Returns () => void

      • (): void
      • Returns void

getStore

  • getStore(): { saveRoute: any; setState: any; hasRoute: any; findRoute: any; toString: any }

onExit

  • onExit(action: HistoryActionType): void
  • Emits the router is deactivated.

    since

    1.0.0

    example
    Router.of({
    routerDidExit: (router, action) => {
    ...
    }
    })
    emits

    routerDidExit

    Parameters

    • action: HistoryActionType

    Returns void

isAnimated

  • isAnimated(): any

isValidPath

  • isValidPath(path: string): boolean
  • Checks if the specified path is valid or not

    since

    1.0.0

    Parameters

    • path: string

    Returns boolean

goBack

  • goBack(url?: string | Location, animated?: boolean): undefined | BottomTabBarRouter<Ttarget>
  • Rewinds one step the history

    since

    1.0.0

    Parameters

    • Optional url: string | Location

      This is an experimental feature. If you use this feature you should use for same StackRouter stack.

    • animated: boolean = true

    Returns undefined | BottomTabBarRouter<Ttarget>

getLocation

  • getLocation(): undefined | Location
  • Returns last location of history

    since

    1.0.0

    Returns undefined | Location

getHistoryasArray

  • getHistoryasArray(): string[]
  • Returns History entries as Array

    since

    1.0.0

    Returns string[]

Properties

map

map: MapFunction<Route<any>>

Static currentRouter

currentRouter: Router<any> | NativeStackRouter<PageImpl>

Static blocker

blocker: null | ((router: Router<unknown>, path: null | string, routeData: null | object, action: HistoryActionType, doneFn: Function) => void)

Optional dispatch

dispatch?: (location: Location, action: HistoryActionType, target: Router<Ttarget>, fromRouter?: boolean) => void

Type declaration

    • (location: Location, action: HistoryActionType, target: Router<Ttarget>, fromRouter?: boolean): void
    • Parameters

      • location: Location
      • action: HistoryActionType
      • target: Router<Ttarget>
      • Optional fromRouter: boolean

      Returns void

emitter

emitter: { emitRouterDidEnter?: RouteLifeCycleHandler<any>; emitRouterDidExit?: (router: Router<unknown>, action: HistoryActionType) => void; emitRouteWillEnter?: any }

Type declaration

  • Optional emitRouterDidEnter?: RouteLifeCycleHandler<any>
  • Optional emitRouterDidExit?: (router: Router<unknown>, action: HistoryActionType) => void
      • (router: Router<unknown>, action: HistoryActionType): void
      • Parameters

        • router: Router<unknown>
        • action: HistoryActionType

        Returns void

  • emitRouteWillEnter?:function
    • emitRouteWillEnter(router: Router<unknown>, route: Route<unknown>, view?: any): void

Accessors

state

  • get state(): RouteState<any>

routePath

  • get routePath(): string | (() => string)
  • Helper method to return excat path of the component

    since

    1.0.0

    Returns string | (() => string)

renderer

  • get renderer(): undefined | default

matches

  • get matches(): MatchReturn

historyController

  • get historyController(): undefined | HistoryController

Constructors

constructor

  • new BottomTabBarRouter<Ttarget>(__namedParameters: BottomTabBarRouterParams<Ttarget>): BottomTabBarRouter<Ttarget>

Events

routeDidEnter

  • routeDidEnter(route: Route<Ttarget>): void
  • Handles route is matched and displayed

    example
    Route.of({
    routeDidEnter: (router, route) => {
    //...
    }
    })
    emits

    routeDidEnter

    Parameters

    Returns void

routeDidExit

  • routeDidExit(parent: Route<Ttarget>): void
  • Handles that route is removed by router

    example
    Route.of({
    routeDidExit: (router, route) => {
    //...
    }
    })
    since

    1.0.0

    emits

    routeDidExit

    Parameters

    Returns void

Generated using TypeDoc