-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[TIMOB-24982] Android/iOS: Add WebView zoomLevel #9226
Changes from 16 commits
9c15b71
c2b5910
5f3b916
ec3faf9
5fbb647
4c75fd3
1b17f3f
26b6280
adba36a
85696af
7a43e59
64d9ac1
884ebb3
bff8cd2
582dc39
30af365
2145a8b
c1a4ff8
0fd721e
1cb5ce3
809281f
bba3c90
26674c7
9ca3005
acd0d8f
18b2d7d
f9a5ae1
fff87a6
1d1f4b5
619bdf7
7f84e75
7fba15b
e2ec1bd
a9f7aff
e892eb6
1158f03
9a356ed
25cf084
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ public class TiUIWebView extends TiUIView | |
private boolean bindingCodeInjected = false; | ||
private boolean isLocalHTML = false; | ||
private HashMap<String, String> extraHeaders = new HashMap<String, String>(); | ||
private float zoomLevel = TiApplication.getInstance().getApplicationContext().getResources().getDisplayMetrics().density; | ||
|
||
private static Enum<?> enumPluginStateOff; | ||
private static Enum<?> enumPluginStateOn; | ||
|
@@ -460,6 +461,12 @@ public void processProperties(KrollDict d) | |
if (d.containsKey(TiC.PROPERTY_DISABLE_CONTEXT_MENU)) { | ||
disableContextMenu = TiConvert.toBoolean(d, TiC.PROPERTY_DISABLE_CONTEXT_MENU); | ||
} | ||
|
||
if (d.containsKey(TiC.PROPERTY_ZOOM_LEVEL)) { | ||
if (Build.VERSION.SDK_INT >= 21) { | ||
zoomBy(getWebView(), TiConvert.toFloat(d,TiC.PROPERTY_ZOOM_LEVEL)); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
|
@@ -491,6 +498,10 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP | |
} | ||
} else if (TiC.PROPERTY_DISABLE_CONTEXT_MENU.equals(key)) { | ||
disableContextMenu = TiConvert.toBoolean(newValue); | ||
} else if (TiC.PROPERTY_ZOOM_LEVEL.equals(key)) { | ||
if (Build.VERSION.SDK_INT >= 21) { | ||
zoomBy(getWebView(), TiConvert.toFloat(newValue, 1.0f)); | ||
} | ||
} else { | ||
super.propertyChanged(key, oldValue, newValue, proxy); | ||
} | ||
|
@@ -504,6 +515,33 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP | |
} | ||
} | ||
|
||
private void zoomBy(WebView webView, float scale) | ||
{ | ||
if (webView != null) { | ||
if (scale < 0.0f) { | ||
scale = 0.0f; | ||
} else if (scale >= 100.0f) { | ||
scale = 100.0f; | ||
} | ||
webView.zoomBy(scale); | ||
} | ||
} | ||
|
||
public void zoomBy(float scale) | ||
{ | ||
zoomBy(getWebView(), scale); | ||
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. This public zoomBy() method is missing an API Level 21 check like how we handle the zoom level property. Either add the API Level check here too or move all the API Level checks to the private zoomBy() method. |
||
} | ||
|
||
public float getZoomLevel() | ||
{ | ||
return zoomLevel; | ||
} | ||
|
||
public void setZoomLevel(float value) | ||
{ | ||
zoomLevel = value; | ||
} | ||
|
||
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. Having a public I recommend that you remove the public float getZoomLevel()
{
return (this.client != null) ? this.client.getZoomLevel() : 1.0f;
} |
||
private boolean mightBeHtml(String url) | ||
{ | ||
String mime = TiMimeTypeHelper.getMimeType(url); | ||
|
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.
The minimum scale needs to be floored to
0.1f
. A value less than this will cause an exception to be thrown.