-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
[Android] Implement addUIBlock to allow third party to resolve a view #8217
Conversation
… by tag Java Android usage example: UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class); uiManager.addUIBlock(new UIBlock() { public void execute (NativeViewHierarchyManager nvhm) { View view = nvhm.resolveView(tag); ...do something with view... } });
👍 I still vote to make the view snapshot part of core since the API for iOS has already been added. |
@christopherdro I understand the idea behind not making react-native too monolithic though. |
@mkonicek Does FB use the snapshot code internally? If not, I volunteer to extract the missing features out to the module once this is in. |
@gre I understand that approach and it makes sense to me with functionalities that do not exist in core for any of the platforms. However, I have to disagree with that if the functionality already exists for one of the platforms within core. Unless the plan is to remove ac12f98 which I doubt is going to happen. |
@christopherdro yup agreed. APIs should eventually converge to implement same features everywhere. |
Assigning to @lexs to review. Would you mind taking a look please? |
@@ -473,4 +473,8 @@ public EventDispatcher getEventDispatcher() { | |||
public void sendAccessibilityEvent(int tag, int eventType) { | |||
mUIImplementation.sendAccessibilityEvent(tag, eventType); | |||
} | |||
|
|||
public void addUIBlock (UIBlock block) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add documentation here? Maybe an example of how you'd expect it to be used?
Code lgtm, can you just add that documentation? I agree we should have this implemented in a single way across platforms, which would hopefully mean implementing it as a separate module in iOS as well at some point. |
@astreet I've added the doc with the description (it's the same of the iOS implementation, turns out it still make sense for the Android implementation :) ) with an Android example. Thanks |
Great, thanks! @facebook-github-bot shipit |
Thanks for importing. If you are an FB employee go to Phabricator to review. |
af28de5
Summary: This PR follows the work started in facebook#6431 but instead of implementing the snapshot for Android, will just allow that feature to be implemented by a third party library. The missing feature is the ability to resolve a View for a given tag integer. which is now possible with a `addUIBlock` on the `UIManagerModule` method where you give a `UIBlock` instance (a new class) that implements a `execute(NativeViewHierarchyManager)` function. This is already possible in iOS API. a third party can use the `addUIBlock` too. I have kept the name `addUIBlock` so it's the same as in the [iOS' API](https://github.com/facebook/react-native/search?q=addUIBlock&type=Code&utf8=%E2%9C%93). --- With this PR a third party lib can now do... ```java UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class); uiManager.addUIBlock(new UIBlock() { public void execute (NativeViewHierarchyManager nvhm) { View view = nvhm.resolveView(tag); ...do something with view... like... screenshot t Closes facebook#8217 Differential Revision: D3469311 Pulled By: astreet fbshipit-source-id: bb56ecc7e8936299337af47ca8114875ee1fd2b0
Summary: This PR follows the work started in facebook#6431 but instead of implementing the snapshot for Android, will just allow that feature to be implemented by a third party library. The missing feature is the ability to resolve a View for a given tag integer. which is now possible with a `addUIBlock` on the `UIManagerModule` method where you give a `UIBlock` instance (a new class) that implements a `execute(NativeViewHierarchyManager)` function. This is already possible in iOS API. a third party can use the `addUIBlock` too. I have kept the name `addUIBlock` so it's the same as in the [iOS' API](https://github.com/facebook/react-native/search?q=addUIBlock&type=Code&utf8=%E2%9C%93). --- With this PR a third party lib can now do... ```java UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class); uiManager.addUIBlock(new UIBlock() { public void execute (NativeViewHierarchyManager nvhm) { View view = nvhm.resolveView(tag); ...do something with view... like... screenshot t Closes facebook#8217 Differential Revision: D3469311 Pulled By: astreet fbshipit-source-id: bb56ecc7e8936299337af47ca8114875ee1fd2b0
@astreet @christopherdro @nicklockwood I've published third party library https://github.com/gre/react-native-view-shot that re-implement part of the takeSnapshot iOS implementation and also have the Android implementation. |
This PR follows the work started in #6431 but instead of implementing the snapshot for Android, will just allow that feature to be implemented by a third party library.
The missing feature is the ability to resolve a View for a given tag integer. which is now possible with a
addUIBlock
on theUIManagerModule
method where you give aUIBlock
instance (a new class) that implements aexecute(NativeViewHierarchyManager)
function.This is already possible in iOS API. a third party can use the
addUIBlock
too.I have kept the name
addUIBlock
so it's the same as in the iOS' API.With this PR a third party lib can now do...
...and we can finally implement that generic view screenshot in a third party library... -> this is a gist implementing it! <-