Options
All
  • Public
  • Public/Protected
  • All
Menu

Class NativeStackRouter<Ttarget>

Creates NavigationController and manages its behavours and routes.

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

var router = Router.of({
path: "/",

routes: [
NativeStackRouter.of(
path: '/pages',
headerBarParams: () => ({
ios: {
translucent: true,
alpha: 1
},
backgroundColor: Color.BLUE,
visible: true
}),
routes: [
Route.of({
path: "/pages/page1",
build((router, route) => {
const Page1 = require('/pages/Page1');
return new Page1(state.data, router);
})
}),
Route.of({
path: "/pages/page2",
build((router, route) => {
const Page2 = require('/pages/Page2');
return new Page2(state.data, router);
});
});
]
)]
});
example
import System from '@smartface/native/device/system';
import Application from '@smartface/native/application';
import AlertView from '@smartface/native/ui/alertview';
import { NativeStackRouter } from '@smartface/router';

import Page1Design from 'generated/page1';

export default class Page1 {
constructor(data, router) {
super();
this._router = router;
if (router instanceof NativeStackRouter) {
router.setHeaderBarParams({visible: false});
}
}
}
since

1.0.0

Type parameters

  • Ttarget = Page

Hierarchy

  • NativeRouterBase<Ttarget>
    • NativeStackRouter

Index

Methods

setHeaderbarProps

  • setHeaderbarProps(props: IHeaderBar): void

Static of

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>

setHeaderBarParams

  • setHeaderBarParams(params: Partial<IHeaderBar>): void

dismiss

  • dismiss(hooks?: DismissHook | (() => void), animated?: boolean): void
  • Closes StackRouter's View if it is opened as modal.

    since

    1.0.0

    Parameters

    • Optional hooks: DismissHook | (() => void)

      Before and after hooks. If Hooks paramter is a function then it is used as before hook.

    • animated: boolean = true

    Returns void

goBack

onRouteEnter

  • onRouteEnter(route: Route<unknown>, requestedUrl: string): void

goBackto

  • goBackto(n: number): void
  • Go back to index

    example
    router.goBackto(-2)
    
    since

    1.1.0

    Parameters

    • n: number

      Amount of back as negative value. If stack length shorter than specified number then the active router does nothing.

    Returns void

goBacktoUrl

  • goBacktoUrl(url: string): void
  • Go back until the url

    example
    router.goBacktoUrl('/back/to/url');
    
    since

    1.1.0

    Parameters

    • url: string

      An url will be matched in the same stack

    Returns void

goBackHome

  • goBackHome(): void

goBacktoHome

  • goBacktoHome(): void

getStepLengthFromCurrent

  • getStepLengthFromCurrent(url: string): number
  • Returns length of the history steps to be needed to receive from current to specified url

    since

    1.1.0

    Parameters

    • url: string

    Returns number

canGoBacktoUrl

  • canGoBacktoUrl(url: string): boolean
  • Tests if desired url is available to go back or not

    since

    1.1.0

    Parameters

    • url: string

      Desired url to test availability to go back

    Returns boolean

resetView

  • resetView(): void

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

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

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

canGoBack

  • canGoBack(n?: number): undefined | boolean
  • it tests that Whether router can go back as n

    example
    router.canGoBack(-3) ? router.goBackto(-3) : // if not, do anything else
    
    since

    1.1.0

    Parameters

    • Optional n: number

      Amount of back as negative value return {boolean}

    Returns undefined | boolean

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

push

  • Pushes new history entry with specified path

    since

    1.0.0

    Parameters

    • path: string

      Path or matches of the route

    • routeData: {} = {}
      • animated: boolean = true

      Returns NativeStackRouter<Ttarget>

    isValidPath

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

      since

      1.0.0

      Parameters

      • path: string

      Returns boolean

    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[]

    dispose

    • dispose(): void

    Properties

    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)

    map

    map: MapFunction<Route<any>>

    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

    Constructors

    constructor

    • new NativeStackRouter<Ttarget>(params: NativeStackRouterParams<PageImpl>): NativeStackRouter<Ttarget>
    • property

      {Page} frompage`

      property

      {Page} topage

      property

      {{operation: number}} operation

      Type parameters

      • Ttarget = PageImpl

      Parameters

      • params: NativeStackRouterParams<PageImpl>

      Returns NativeStackRouter<Ttarget>

    Accessors

    bottomSheetOptions

    • get bottomSheetOptions(): { cornerRadius?: number; detents?: [primaryDetent: BottomSheetDetent, secondaryDetent?: BottomSheetDetent]; isGrabberVisible?: boolean }
    • Returns { cornerRadius?: number; detents?: [primaryDetent: BottomSheetDetent, secondaryDetent?: BottomSheetDetent]; isGrabberVisible?: boolean }

      • Optional cornerRadius?: number
      • Optional detents?: [primaryDetent: BottomSheetDetent, secondaryDetent?: BottomSheetDetent]
      • Optional isGrabberVisible?: boolean

    modalOptions

    • get modalOptions(): any

    headerBarParams

    • get headerBarParams(): undefined | Partial<IHeaderBar>

    modalType

    • get modalType(): ModalType

    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

    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