Skip to content

BackHandler Fix#122

Open
kadirmertgul wants to merge 2 commits intorishabhbhatia:masterfrom
kadirmertgul:master
Open

BackHandler Fix#122
kadirmertgul wants to merge 2 commits intorishabhbhatia:masterfrom
kadirmertgul:master

Conversation

@kadirmertgul
Copy link
Copy Markdown

I made the necessary changes to fix crashes in my React Native project caused by the back button on Android devices and the closing of Awesome Alerts using BackHandler.

@foxriver76
Copy link
Copy Markdown

foxriver76 commented Jun 27, 2025

Any possibility to get this fix in @rishabhbhatia? without it the lib won't work for up-to-date RN projects.

export default class AwesomeAlert extends Component {
constructor(props) {
super(props);
this.backHandlerSubscription = null; // ✅ Değişkeni baştan tanımla
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.backHandlerSubscription = null; // ✅ Değişkeni baştan tanımla
this.backHandlerSubscription = null;

} = data;

return (
<TouchableOpacity style={[styles.button, { backgroundColor }, buttonStyle]} testID={testID} onPress={onPress}>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems unnecessary, can we fix the linting here back to original

};

return (
<View style={[styles.container, alertContainerStyle]}>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems unnecessary, can we fix the linting here back to original

</Modal>
) : this._renderAlert()
: null;
wrapInModal ? (
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same feedback for linting, keep the original


componentWillUnmount() {
HwBackHandler.removeEventListener(HW_BACK_EVENT, this._handleHwBackEvent);
this.backHandlerSubscription?.remove(); // ✅ Eğer varsa kaldır
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.backHandlerSubscription?.remove(); // ✅ Eğer varsa kaldır
this.backHandlerSubscription?.remove();

HwBackHandler.removeEventListener(HW_BACK_EVENT, this._handleHwBackEvent);
this.backHandlerSubscription?.remove(); // ✅ Eğer varsa kaldır
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems unnecessary, can we keep the original

@rishabhbhatia
Copy link
Copy Markdown
Owner

rishabhbhatia commented Jul 4, 2025

I see a First-time contributor badge on @kadirmertgul, so i'd love for you to have this contribution commit. I'll wait a bit to see if you have the time and resources to make the changes needed here. Overall the change makes sense to me!

@foxriver76 for sure, happy to merge these and release a new version once the necessary changes are made on this PR.

Applied requested changes: removed comments, reverted linting, fixed props.show init
@kadirmertgul
Copy link
Copy Markdown
Author

Hey @rishabhbhatia, thanks for the feedback!

✅ I’ve made all the requested changes:

Removed all the // comments for clarity.

Reverted the unnecessary lint changes back to the original formatting.

Set showSelf to initialize from props.show as suggested.

Let me know if there’s anything else I should adjust. Thanks again for your time and for considering the PR!

Copy link
Copy Markdown
Owner

@rishabhbhatia rishabhbhatia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for making those changes. Same feedback as before, we'd want to remove all the extra code linting that's bloating the diff. One additional comment on an extra change made to showSelf.

If i had to guess, it might be your IDE auto-linting the file with your local settings once you finish making the changes. Look for the option to save without formatting. With the current change you would see the test fail too.

my expectation from this PR would be to consist a change for initialize the backhandler, subscribe to it when component mounts and remove the subscription on unmount.

this.state = {
showSelf: false,
};
this.state = {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be reverted back to how it was before


return (
<TouchableOpacity style={[styles.button, { backgroundColor }, buttonStyle]} testID={testID} onPress={onPress}>
<TouchableOpacity style={[styles.button, { backgroundColor }, buttonStyle]} testID={testID} onPress={onPress}>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's still an extra space here that makes this change show up in the diff of the PR. If you remove that extra spacing, this would not show up here. Thats the state we'd want to be in.

Suggested change
<TouchableOpacity style={[styles.button, { backgroundColor }, buttonStyle]} testID={testID} onPress={onPress}>
<TouchableOpacity style={[styles.button, { backgroundColor }, buttonStyle]} testID={testID} onPress={onPress}>

</View>
</Animated.View>
</View>
<View style={[styles.container, alertContainerStyle]}>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, the green square you're seeing is the extra unwanted spacing that we want to remove. This change should not show up in the PR diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants