Skip to content

Commit

Permalink
Merge pull request #301 from gree/fix/android_margin_adjustment_for_k…
Browse files Browse the repository at this point in the history
…eyboard

trying to fix layout issues for orientation changes which may happen on resume.
  • Loading branch information
KojiNakamaru committed Apr 1, 2018
2 parents a279a60 + 5227171 commit de9a25c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
Binary file modified dist/unity-webview.unitypackage
Binary file not shown.
Binary file modified dist/unity-webview.zip
Binary file not shown.
53 changes: 44 additions & 9 deletions plugins/WebViewObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,36 @@ public class WebViewObject : MonoBehaviour
#elif UNITY_ANDROID
AndroidJavaObject webView;

bool mIsKeyboardVisible0 = false;
bool mIsKeyboardVisible = false;
bool mVisibility;
bool mIsKeyboardVisible0;
bool mIsKeyboardVisible;
float mResumedTimestamp;

void OnApplicationPause(bool paused)
{
if (webView == null)
return;
if (paused)
{
webView.Call("SetVisibility", false);
}
else
{
mResumedTimestamp = Time.realtimeSinceStartup;
}
}

void Update()
{
if (webView == null)
return;
if (mResumedTimestamp != 0.0f && Time.realtimeSinceStartup - mResumedTimestamp > 0.5f)
{
mResumedTimestamp = 0.0f;
webView.Call("SetVisibility", mVisibility);
}
}

/// Called from Java native plugin to set when the keyboard is opened
public void SetKeyboardVisible(string pIsVisible)
{
Expand Down Expand Up @@ -391,29 +418,36 @@ public void SetCenterPositionWithScale(Vector2 center, Vector2 scale)
public void SetMargins(int left, int top, int right, int bottom)
{
#if UNITY_WEBPLAYER
Application.ExternalCall("unityWebView.setMargins", name, left, top, right, bottom);
#elif UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
//TODO: UNSUPPORTED
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
if (webView == IntPtr.Zero)
return;
int width = Screen.width - (left + right);
int height = Screen.height - (bottom + top);
_CWebViewPlugin_SetRect(webView, width, height);
rect = new Rect(left, bottom, width, height);
#elif UNITY_IPHONE
if (webView == IntPtr.Zero)
return;
_CWebViewPlugin_SetMargins(webView, left, top, right, bottom);
#elif UNITY_ANDROID
if (webView == null)
return;
webView.Call("SetMargins", left, top, right, AdjustBottomMargin(bottom));
#endif
mMarginLeft = left;
mMarginTop = top;
mMarginRight = right;
mMarginBottom = bottom;
#if UNITY_WEBPLAYER
Application.ExternalCall("unityWebView.setMargins", name, left, top, right, bottom);
#elif UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
//TODO: UNSUPPORTED
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
int width = Screen.width - (left + right);
int height = Screen.height - (bottom + top);
_CWebViewPlugin_SetRect(webView, width, height);
rect = new Rect(left, bottom, width, height);
#elif UNITY_IPHONE
_CWebViewPlugin_SetMargins(webView, left, top, right, bottom);
#elif UNITY_ANDROID
webView.Call("SetMargins", left, top, right, AdjustBottomMargin(bottom));
#endif
}

public void SetVisibility(bool v)
Expand All @@ -433,6 +467,7 @@ public void SetVisibility(bool v)
#elif UNITY_ANDROID
if (webView == null)
return;
mVisibility = v;
webView.Call("SetVisibility", v);
#endif
visibility = v;
Expand Down

0 comments on commit de9a25c

Please sign in to comment.