ViewPump icon indicating copy to clipboard operation
ViewPump copied to clipboard

Multiple `ViewPump` instances

Open badoualy opened this issue 6 years ago • 2 comments

From what I gathered from the doc and source code, currently we call only call ViewPump.init once, and have only one configuration

If we want to add some new interceptors later, we have to call init again after getting currently installed interceptors, and add them in the new config

It also means that having an activity specific configuration while maintaining an app wide configuration is possible but complicated

In my case, I have an app-wide configuration, and for one activity, I have to override a specific widget with my own version

  • One solution could be to add a ViewPump parameter to the ViewPumpContextWrapper#wrap method, and then inject the ViewPump instance into ViewPumpLayoutInflater, and by default make it use ViewPump.get()
  • This change would also mean that the resolution would be eager, and thus after creating the wrapped context, changes to ViewPump wouldn't affect it anymore. An easy solution would be to inject null in the ViewPumpLayoutInflater, and when creating a view, if the instance is null, fallback to ViewPump.get() as before. This would prevent any behavior changes

badoualy avatar Apr 19 '19 12:04 badoualy

This is not something that we are looking to support

jbarr21 avatar May 30 '19 22:05 jbarr21

For anyone with the same use-case, one other alternative is to code an interceptor that would do nothing when the current context is not an instance of the wanted activity (unwrapping ContextWrapper, ...).

I'll post the snippet when I'll have time to code it

badoualy avatar Jun 06 '19 21:06 badoualy