Skip to content
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

feat(ios): expose new iOS 14 APIs in Ti.UI.WebView #11834

Merged
merged 22 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4016622
feat(ios): expose new iOS 14 APIs in TI.UI.WebView
vijaysingh-axway Jul 22, 2020
ee68717
style: fixed indentation issue
vijaysingh-axway Jul 22, 2020
24c6be8
Merge branch 'master' into TIMOB-27987_1
vijaysingh-axway Jul 22, 2020
19656c0
feat(ios): expose new iOS 14 APIs in TI.UI.WebView
vijaysingh-axway Jul 22, 2020
a277c5e
feat(ios): add optional parameters in string search
vijaysingh-axway Jul 23, 2020
6fb29d3
docs(ios): added docs
vijaysingh-axway Jul 23, 2020
19f236d
style: fixed linting issue
vijaysingh-axway Jul 23, 2020
be5a2ab
test(ios): added unit test
vijaysingh-axway Jul 23, 2020
6a0896b
style: fixed linting issue
vijaysingh-axway Jul 24, 2020
406da87
Merge branch 'master' into TIMOB-27987_1
vijaysingh-axway Jul 27, 2020
f803de3
test(ios): added unit test
vijaysingh-axway Jul 27, 2020
f0d3000
style: fixed linting issue
vijaysingh-axway Jul 29, 2020
3db436c
test(ios): fixed unit tests
vijaysingh-axway Jul 29, 2020
20e1776
ci(jenkins): use node with xcode 12
vijaysingh-axway Jul 29, 2020
09f2935
Merge branch 'master' into TIMOB-27987_1
vijaysingh-axway Aug 6, 2020
7288e78
test(ios): use new constant to check major version
vijaysingh-axway Aug 7, 2020
be216bf
Merge branch 'master' into TIMOB-27987_1
vijaysingh-axway Aug 14, 2020
59347eb
test(ios): updated unit tests
vijaysingh-axway Aug 19, 2020
26467be
test(ios): updated unit tests
vijaysingh-axway Aug 19, 2020
58e1fb6
Merge branch 'master' into TIMOB-27987_1
vijaysingh-axway Aug 19, 2020
e041b6a
Merge branch 'master' into TIMOB-27987_1
vijaysingh-axway Aug 21, 2020
a80e6e9
Merge branch 'master' into TIMOB-27987_1
sgtcoolguy Aug 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to include an example in the docs showing how to call this method and then write the blob to a file in the callback.

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear to me from the apple docs or looking at our code exactly how this would be used to load into a web view.

Presumably we can save this to a file, great - but how do we then load the file or blob and set it in a web view later? Can we simply provide the Ti.Filesystem.File or Ti.Blob we received as the Ti.UI.WebView.data property and it magically works? If so, perhaps we can provide an example in the docs here and add a unit test which does so?

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extend ErrorResponse? (I guess we don't set a code property, though?)

May make more sense to align this consistently, though, by doing so.

summary: The parameter passed to the <Titanium.UI.WebView.createPDF> or <Titanium.UI.WebView.createWebArchive>callback.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
summary: The parameter passed to the <Titanium.UI.WebView.createPDF> or <Titanium.UI.WebView.createWebArchive>callback.
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