-
Notifications
You must be signed in to change notification settings - Fork 1k
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): Add automatic Date serialization to bridge communication #4177
Merged
Conversation
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
jcesarmobile
approved these changes
Feb 16, 2021
imhoffd
approved these changes
Feb 16, 2021
This looks good! However, the new default behavior breaks some things in local-notifications based on my tests (and potentially other core plugins). Should we hold off on merging this in until we review / fix any breaking changes in our plugins, or do it now and fix any issues as they come up (hopefully before the next beta)? |
theproducer
approved these changes
Feb 18, 2021
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently,
WKWebView
will automatically translate JavaScriptDate
objects to NSDate/Date objects when sending data over the bridge from JavaScript -> Native. While this might be helpful it is potentially unexpected, and it is inconsistent with Android where theDates
are turned into strings. Dates are not handled at all when sending Native -> JavaScript and including a Date in the result dictionary will cause an exception to be thrown during serialization.So, this branch does 3 things related to Dates and returning the result of a plugin call.
It serializes Dates in plugin calls during type coercion. This operation is not performed for Cordova plugins to preserve backwards compatibility. In addition, a plugin can opt-out of the new behavior by setting its
shouldStringifyDatesInCalls
property to false.It serializes Dates in result dictionaries automatically. A date in will result in an ISO 8601 string out in both directions now. Since the previous behavior was an error, there is no compatibility concerns and plugins can opt out of the serialization by transforming the dates before inserting them into the results.
It refactors some of the calling objects in service of 2, as well as to prepare for
Codable
support in the future and paying down tech debt:The declaration/implementation of
CAPPluginCallResult
andCAPPluginCallError
have been moved from Obj-C to Swift. This keeps the same Obj-C interface but allows them to use new swift types internally.PluginCallResult
is a new Swift enum to wrap result dictionaries that can be extended to support additional types (such asEncodable
objects in future work).Multiple
typealias
types have been consolidated.JSCall
,JSResult
, andJSResultError
classes have all been refactored intointernal
immutable structs. Since the methods that use those objects are allinternal
, it made no sense for them to be public. That is technically a breaking change but there is no reason for external code to be referencing them.Some of the surrounding code has been cleaned up to become more idiomatic and to remove force-unwraps and unused code.
Closes #4160
Documentation update: ionic-team/capacitor-site#207