Skip to content

Commit

Permalink
feat(app): Add canGoBack to backButton event (#265)
Browse files Browse the repository at this point in the history

Co-authored-by: jcesarmobile <[email protected]>
  • Loading branch information
lishid and jcesarmobile authored May 18, 2021
1 parent 95920da commit 6d7861e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
9 changes: 8 additions & 1 deletion app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ Remove all native listeners for this plugin
| **`error`** | <code>{ message: string; }</code> | If the plugin call didn't succeed, it will contain the error message. | 1.0.0 |


#### BackButtonListenerEvent

| Prop | Type | Description | Since |
| --------------- | -------------------- | --------------------------------------------------------------------------------------------------------- | ----- |
| **`canGoBack`** | <code>boolean</code> | Indicates whether the browser can go back in history. False when the history stack is on the first entry. | 1.0.0 |


### Type Aliases


Expand All @@ -341,6 +348,6 @@ Remove all native listeners for this plugin

#### BackButtonListener

<code>(): void</code>
<code>(event: <a href="#backbuttonlistenerevent">BackButtonListenerEvent</a>): void</code>

</docgen-api>
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public void handleOnBackPressed() {
bridge.getWebView().goBack();
}
} else {
notifyListeners(EVENT_BACK_BUTTON, new JSObject(), true);
JSObject data = new JSObject();
data.put("canGoBack", bridge.getWebView().canGoBack());
notifyListeners(EVENT_BACK_BUTTON, data, true);
bridge.triggerJSEvent("backbutton", "document");
}
}
Expand Down
12 changes: 11 additions & 1 deletion app/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,20 @@ export interface RestoredListenerEvent {
};
}

export interface BackButtonListenerEvent {
/**
* Indicates whether the browser can go back in history.
* False when the history stack is on the first entry.
*
* @since 1.0.0
*/
canGoBack: boolean;
}

export type StateChangeListener = (state: AppState) => void;
export type URLOpenListener = (event: URLOpenListenerEvent) => void;
export type RestoredListener = (event: RestoredListenerEvent) => void;
export type BackButtonListener = () => void;
export type BackButtonListener = (event: BackButtonListenerEvent) => void;

export interface AppPlugin {
/**
Expand Down

0 comments on commit 6d7861e

Please sign in to comment.