Skip to content

Commit

Permalink
feat(ios): expose new iOS 14 APIs in Ti.UI.WebView (#11834)
Browse files Browse the repository at this point in the history
Fixes TIMOB-27987
  • Loading branch information
vijaysingh-axway committed Sep 2, 2020
1 parent 09b4591 commit 840b0d2
Show file tree
Hide file tree
Showing 4 changed files with 399 additions and 66 deletions.
103 changes: 103 additions & 0 deletions apidoc/Titanium/UI/WebView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,48 @@ methods:
returns:
type: BackForwardList

- name: createPDF
summary: |
Create a PDF document representation from the web page currently displayed in the WebView.
description: |
If the data is written to a file the resulting file is a valid PDF document.
platforms: [iphone, ipad]
since: "9.2.0"
osver: {ios: {min: "14.0"}}
parameters:
- name: callback
summary: Function to call upon pdf creation.
type: Callback<DataCreationResult>

- name: createWebArchive
summary: Create WebKit web archive data representing the current web content of the WebView.
description: |
WebKit web archive data represents a snapshot of web content. It can be loaded into a WebView directly,
and saved to a file for later use.
platforms: [iphone, ipad]
since: "9.2.0"
osver: {ios: {min: "14.0"}}
parameters:
- name: callback
summary: Function to call upon web archive creation.
type: Callback<DataCreationResult>

- name: findString
summary: Searches the page contents for the given string.
platforms: [iphone, ipad]
since: "9.2.0"
osver: {ios: {min: "14.0"}}
parameters:
- name: searchString
summary: The string to search for.
type: String
- name: options
summary: Options for search.
type: StringSearchOptions
optional: true
- name: callback
summary: Function to call upon search finished.
type: Callback<SearchResult>
events:
- name: beforeload
summary: Fired before the web view starts loading its content.
Expand Down Expand Up @@ -1114,6 +1156,67 @@ properties:
description: May be undefined.
type: String

---
name: DataCreationResult
summary: The parameter passed to the <Titanium.UI.WebView.createPDF> or <Titanium.UI.WebView.createWebArchive>callback.
platforms: [iphone, ipad]
since: "9.2.0"
properties:
- name: data
summary: The created data.
type: Titanium.Blob
- name: success
summary: Indicates if the data creation successful or not.
description: Returns `true` on successful creation, otherwise `false`.
type: Boolean
- name: error
summary: Error message, if any returned.
description: May be undefined.
type: String

---
name: SearchResult
summary: The parameter passed to the <Titanium.UI.WebView.findString>.
platforms: [iphone, ipad]
since: "9.2.0"
properties:
- name: success
summary: Indicates if string found or not.
description: Returns `true` if found, otherwise `false`.
type: Boolean
- name: error
summary: Error message, if any returned.
description: May be undefined.
type: String

---
name: StringSearchOptions
summary: |
The optional options to pass to the <Titanium.UI.WebView.findString>. Pass a
dictionary with one or more of the following string-keys:
* `caseSensitive` (Boolean value)
* `backward` (Boolean value)
* `wraps` (Boolean value)
properties:
- name: caseSensitive
summary: Whether or not the search should be case sensitive.
type: Boolean
default: false
optional: true

- name: backward
type: Boolean
summary: |
The direction to search from the current selection. The search will respect the writing direction of the document
default: false
optional: true

- name: wraps
summary: Whether the search should start at the beginning of the document once it reaches the end.
type: Boolean
default: true
optional: true

---
name: BackForwardList
summary: The object returned to the <Titanium.UI.WebView.backForwardList> method.
Expand Down
12 changes: 10 additions & 2 deletions iphone/Classes/TiUIWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ - (void)setHandlePlatformUrl_:(id)arg
- (void)setZoomLevel_:(id)zoomLevel
{
ENSURE_TYPE(zoomLevel, NSNumber);

#if IS_SDK_IOS_14
if ([TiUtils isIOSVersionOrGreater:@"14.0"]) {
[self webView].pageZoom = [zoomLevel floatValue];
return;
}
#endif
[[self webView] evaluateJavaScript:[NSString stringWithFormat:@"document.body.style.zoom = %@;", zoomLevel]
completionHandler:nil];
}
Expand Down Expand Up @@ -223,9 +228,11 @@ - (void)setData_:(id)value
}

NSData *data = nil;
NSString *mimeType = nil;

if ([value isKindOfClass:[TiBlob class]]) {
data = [(TiBlob *)value data];
mimeType = [(TiBlob *)value mimeType];
} else if ([value isKindOfClass:[TiFile class]]) {
#ifdef USE_TI_FILESYSTEM
data = [[(TiFilesystemFileProxy *)value blob] data];
Expand All @@ -237,8 +244,9 @@ - (void)setData_:(id)value
[_webView.configuration.userContentController removeScriptMessageHandlerForName:@"_Ti_"];
[_webView.configuration.userContentController addScriptMessageHandler:self name:@"_Ti_"];

mimeType = mimeType ?: [self mimeTypeForData:data];
[[self webView] loadData:data
MIMEType:[self mimeTypeForData:data]
MIMEType:mimeType
characterEncodingName:@"UTF-8"
baseURL:[[NSBundle mainBundle] resourceURL]];
}
Expand Down
Loading

0 comments on commit 840b0d2

Please sign in to comment.