Skip to content

Commit

Permalink
comments for nav actions added
Browse files Browse the repository at this point in the history
  • Loading branch information
kanzitelli committed Oct 1, 2022
1 parent b1e743c commit e16e06f
Showing 1 changed file with 48 additions and 11 deletions.
59 changes: 48 additions & 11 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -382,49 +382,96 @@ export class Navio<
// ===========
// | Actions |
// ===========
/**
* `push(...)` is used to navigate to a new screen in the stack.
*
* @param name ScreenName
* @param props Props
*/
push<T extends ScreenName, Props extends object | undefined>(name: T, props?: Props) {
if (this.isNavReady) {
this.navRef.current?.dispatch(StackActions.push(name as string, props));
}
}

/**
* `pushStack(...)` is used to navigate to a new stack. It will "hide" tabs.
*
* @param name StackName
*/
pushStack<T extends StackName>(name: T) {
if (this.isNavReady) {
this.navigate(name);
}
}

/**
* `goBack()` is used to navigate back in the stack.
*/
goBack() {
if (this.isNavReady) {
this.navRef.current?.goBack();
}
}

/**
* `pop(...)` is used to navigate to a previous screen in the stack.
*
* @param count number
*/
pop(count?: number) {
if (this.isNavReady) {
this.navRef.current?.dispatch(StackActions.pop(count));
}
}

/**
* `popToPop()` is used to navigate to the first screen in the stack, dismissing all others.
*/
popToTop() {
if (this.isNavReady) {
this.navRef.current?.dispatch(StackActions.popToTop());
}
}

/**
* `show(...)` is used to show a modal.
*
* @param name ModalName
*/
show<T extends ModalName>(name: T) {
if (this.isNavReady) {
this.navigate(name);
}
}

/**
* `jumpTo(...)` is used to change the current tab.
*
* @param name TabName
*/
jumpTo<T extends TabName>(name: T) {
if (this.isNavReady) {
this.navRef.current?.dispatch(TabActions.jumpTo(name as string));
}
}

navigate = <
/**
* `setRoot(...)` is used to set a new root of the app. It can be used to switch Auth and App stacks.
*
* @param name 'Tabs' | StackName
*/
setRoot<T extends RootName>(name: T) {
if (this.isNavReady) {
this.navRef.current?.dispatch(
CommonActions.reset({
routes: [{name}],
}),
);
}
}

private navigate = <
T extends ScreenName | StackName | TabName | ModalName,
Props extends object | undefined,
>(
Expand All @@ -441,16 +488,6 @@ export class Navio<
}
};

setRoot<T extends RootName>(name: T) {
if (this.isNavReady) {
this.navRef.current?.dispatch(
CommonActions.reset({
routes: [{name}],
}),
);
}
}

// System
private log(message: string, type: 'log' | 'warn' | 'error' = 'log') {
console[type](`[navio] ${message}`);
Expand Down

0 comments on commit e16e06f

Please sign in to comment.