forked from react-native-webview/react-native-webview
-
Notifications
You must be signed in to change notification settings - Fork 8
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] Add rebind method #22
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d795d88
Android add update function
matthova 74d06fe
Add javascript for rebind
matthova 413d684
Add compiled results
matthova acca81f
Add example
matthova 880616a
fix layout changes
04e7991
ensure the parent is already attached to window
2b2480f
some fixes
60cb017
revert Portals.tsx
18f9178
remove diff
08e7c4a
build
e564941
unused import
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package com.reactnativecommunity.webview; | ||
|
||
import android.view.View; | ||
import android.webkit.WebView; | ||
import android.widget.FrameLayout; | ||
|
||
|
@@ -8,20 +9,77 @@ | |
import com.facebook.common.logging.FLog; | ||
import com.facebook.react.uimanager.ThemedReactContext; | ||
|
||
import java.util.Map; | ||
|
||
public class RNCWebView extends FrameLayout { | ||
private static final String TAG = "RNCWebView"; | ||
public static final int INVALID_VIEW_ID = -1; | ||
|
||
private String webViewKey; | ||
private RNCWebViewManager.InternalWebView internalWebView; | ||
|
||
public RNCWebView(ThemedReactContext reactContext) { | ||
super(reactContext); | ||
|
||
// There is an issue with react-native where if a view is moved | ||
// the parent and children views are not resized | ||
// Since we are moving views outside of React, the layout request might be dropped | ||
// on a normal add/remove view | ||
// By calling .layout directly on the parent, it'll force the layout change | ||
// See this issue for more context: https://github.com/facebook/react-native/issues/17968 | ||
setOnHierarchyChangeListener(new OnHierarchyChangeListener() { | ||
@Override | ||
public void onChildViewAdded(View parent, View child) { | ||
if (parent != null) { | ||
parent.measure( | ||
MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY), | ||
MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY) | ||
); | ||
parent.layout(0, 0, parent.getMeasuredWidth(), parent.getMeasuredHeight()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: It may be slightly more readable to name the l / t / r / b parameters inline with code comments sort of like this.
|
||
} | ||
} | ||
|
||
@Override | ||
public void onChildViewRemoved(View parent, View child) {} | ||
}); | ||
} | ||
|
||
@Override | ||
protected void onAttachedToWindow() { | ||
super.onAttachedToWindow(); | ||
|
||
if (webViewKey == null) return; | ||
|
||
Map<String, WebView> internalWebViewMap = RNCWebViewMapManager.INSTANCE.getInternalWebViewMap(); | ||
Map<String, RNCWebView> rncWebViewMap = RNCWebViewMapManager.INSTANCE.getRncWebViewMap(); | ||
|
||
// If there is an existing RNCWebView that has an internal webview, re-attach it to this view | ||
if (rncWebViewMap.containsKey(webViewKey)) { | ||
RNCWebView existingView = rncWebViewMap.get(webViewKey); | ||
RNCWebViewManager.InternalWebView existingInternalWebView = existingView.detachWebView(); | ||
attachWebView(existingInternalWebView); | ||
|
||
// If there is a detached internal webview attach it to this RNCWebView | ||
} else if (internalWebViewMap.containsKey(webViewKey)) { | ||
RNCWebViewManager.InternalWebView webView = (RNCWebViewManager.InternalWebView) internalWebViewMap.get(webViewKey); | ||
attachWebView(webView); | ||
} | ||
|
||
if (internalWebView != null) { | ||
internalWebView.setWebViewKey(webViewKey); | ||
RNCWebViewMapManager.INSTANCE.getViewIdMap().put(internalWebView.getId(), this.getId()); | ||
internalWebViewMap.put(webViewKey, internalWebView); | ||
rncWebViewMap.put(webViewKey, this); | ||
} | ||
} | ||
|
||
public interface Action { | ||
void apply(RNCWebViewManager.InternalWebView webView); | ||
} | ||
|
||
public void setWebViewKey(String webViewKey) { | ||
this.webViewKey = webViewKey; | ||
} | ||
|
||
/** | ||
* Attaches a {@link RNCWebViewManager.InternalWebView} to the RNCWebView parent | ||
* Throws an exception if the provided internal webView is already attached to a parent | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
facebook/react-native#17968 (comment)
Wow, same. Anyway, nice work on identifying this issue, and I'm glad calling
layout
directly fixes this!