Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove BackHandler.removeEventListener method for RN 0.77+ #4475

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 26 additions & 31 deletions docs/backhandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,34 @@ The event subscriptions are called in reverse order (i.e. the last registered su
## Pattern

```tsx
BackHandler.addEventListener('hardwareBackPress', function () {
/**
* this.onMainScreen and this.goBack are just examples,
* you need to use your own implementation here.
*
* Typically you would use the navigator here to go to the last state.
*/

if (!this.onMainScreen()) {
this.goBack();
const subscription = BackHandler.addEventListener(
'hardwareBackPress',
function () {
/**
* When true is returned the event will not be bubbled up
* & no other back action will execute
* this.onMainScreen and this.goBack are just examples,
* you need to use your own implementation here.
*
* Typically you would use the navigator here to go to the last state.
*/
return true;
}
/**
* Returning false will let the event to bubble up & let other event listeners
* or the system's default back action to be executed.
*/
return false;
});

if (!this.onMainScreen()) {
this.goBack();
/**
* When true is returned the event will not be bubbled up
* & no other back action will execute
*/
return true;
}
/**
* Returning false will let the event to bubble up & let other event listeners
* or the system's default back action to be executed.
*/
return false;
},
);

// Unsubscribe the listener on unmount
subscription.remove();
```

## Example
Expand Down Expand Up @@ -126,14 +132,3 @@ static addEventListener(
```tsx
static exitApp();
```

---

### `removeEventListener()`

```tsx
static removeEventListener(
eventName: BackPressEventName,
handler: () => boolean | null | undefined,
);
```
57 changes: 26 additions & 31 deletions website/versioned_docs/version-0.77/backhandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,34 @@ The event subscriptions are called in reverse order (i.e. the last registered su
## Pattern

```tsx
BackHandler.addEventListener('hardwareBackPress', function () {
/**
* this.onMainScreen and this.goBack are just examples,
* you need to use your own implementation here.
*
* Typically you would use the navigator here to go to the last state.
*/

if (!this.onMainScreen()) {
this.goBack();
const subscription = BackHandler.addEventListener(
'hardwareBackPress',
function () {
/**
* When true is returned the event will not be bubbled up
* & no other back action will execute
* this.onMainScreen and this.goBack are just examples,
* you need to use your own implementation here.
*
* Typically you would use the navigator here to go to the last state.
*/
return true;
}
/**
* Returning false will let the event to bubble up & let other event listeners
* or the system's default back action to be executed.
*/
return false;
});

if (!this.onMainScreen()) {
this.goBack();
/**
* When true is returned the event will not be bubbled up
* & no other back action will execute
*/
return true;
}
/**
* Returning false will let the event to bubble up & let other event listeners
* or the system's default back action to be executed.
*/
return false;
},
);

// Unsubscribe the listener on unmount
subscription.remove();
```

## Example
Expand Down Expand Up @@ -126,14 +132,3 @@ static addEventListener(
```tsx
static exitApp();
```

---

### `removeEventListener()`

```tsx
static removeEventListener(
eventName: BackPressEventName,
handler: () => boolean | null | undefined,
);
```