badoo/Decompose

Back button handling shouldn't be part of the main API

AzimMuradov opened this issue · 2 comments

I think since Decompose is a multiplatform library, special "back button handling" seems unnecessary or even overkill. I think it should be deprecated, or at least moved to a separate library extension provided by another artifact.

Thank you for the request for API improvements, such requests are very valuable. I have considered the concern and decided to keep this API as it is.

Rationale: the back button handling is applicable not only for Android, but for other platform as well. E.g. there are TVs, watches, kiosks with hardware buttons, embedded devices, etc. I understand that this feature is rarely used outside of Android, but still there are possible cases.

Here is additional background. BackPressedDispatcher is already moved to the separate back-pressed module of the Essenty library. The main decompose module depends as api on the back-pressed module.

Why decompose depends on back-pressed? Because the Router controls child component's BackPressedHandlers. Without this dependency, clients will have to pass BackPressedHandler manually via constructors. And what is more important, they will have to manage child BackPressedHandlers manually. When a child component is destroyed, all references to its personal BackPressedHandler should be released, to avoid memory leaks.

Why back-pressed is api dependency? BackPressedHandler is part of the public API, e.g. it is exposed from ComponentContext as a property. So this dependency is for convenience, for clients to use the public API smoothly.

Thanks for the detailed answer!