-
Notifications
You must be signed in to change notification settings - Fork 57
Fix requestImport call to send the correct arguments. #1494
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
Changes from all commits
67d2796
b8f574b
65964a8
9624986
a4bab40
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 |
|---|---|---|
|
|
@@ -27,17 +27,20 @@ public class RNReactNativeGutenbergBridge: RCTEventEmitter { | |
| callback(nil) | ||
| return | ||
| } | ||
| if (allowMultipleSelection) { | ||
| let formattedMedia = media.map { (id, url, type) in | ||
| return [mediaDictKeys.IDKey: id, mediaDictKeys.URLKey: url, mediaDictKeys.TypeKey: type] | ||
| } | ||
| callback([formattedMedia]) | ||
| let mediaToReturn: [MediaInfo] | ||
| if allowMultipleSelection { | ||
| mediaToReturn = media | ||
| } else { | ||
| guard let (mediaID, mediaURL, mediaType) = media.first else { | ||
| callback(nil) | ||
| return | ||
| } | ||
| callback([[mediaDictKeys.IDKey: mediaID, mediaDictKeys.URLKey: mediaURL, mediaDictKeys.TypeKey: mediaType]]) | ||
| mediaToReturn = Array(media.prefix(1)) | ||
| } | ||
|
|
||
| let jsFormattedMedia = mediaToReturn.map { mediaInfo in | ||
| return mediaInfo.encodeForJS() | ||
| } | ||
| if allowMultipleSelection { | ||
| callback([jsFormattedMedia]) | ||
| } else { | ||
| callback(jsFormattedMedia) | ||
|
Comment on lines
+40
to
+43
Contributor
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. It might be good to merge this and send the full array. If multi select is false, the callback should bring just one media item. Maybe we can enforce that via the callback signature, and keep the bridge simpler 🤔 Again, thinking about the future!
Contributor
Author
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. We don't have control on the callback interface it's defined by RN library.
Contributor
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. Let's do that! On another PR someday in the future 😬 |
||
| } | ||
| }) | ||
| } | ||
|
|
@@ -50,12 +53,12 @@ public class RNReactNativeGutenbergBridge: RCTEventEmitter { | |
| return | ||
| } | ||
| DispatchQueue.main.async { | ||
| self.delegate?.gutenbergDidRequestImport(from: url, with: { mediaList in | ||
| guard let mediaList = mediaList else { | ||
| self.delegate?.gutenbergDidRequestImport(from: url, with: { mediaInfo in | ||
| guard let mediaInfo = mediaInfo else { | ||
| callback(nil) | ||
| return | ||
| } | ||
| callback(mediaList) | ||
| } | ||
| callback([mediaInfo.id as Any, mediaInfo.url as Any]) | ||
| }) | ||
| } | ||
| } | ||
|
|
@@ -197,3 +200,14 @@ extension RNReactNativeGutenbergBridge { | |
| static let TypeKey = "type" | ||
| } | ||
| } | ||
|
|
||
| extension MediaInfo { | ||
|
|
||
| func encodeForJS() -> [String: Any] { | ||
| return [ | ||
| RNReactNativeGutenbergBridge.mediaDictKeys.IDKey: id as Any, | ||
| RNReactNativeGutenbergBridge.mediaDictKeys.URLKey: url as Any, | ||
| RNReactNativeGutenbergBridge.mediaDictKeys.TypeKey: type as Any | ||
| ] | ||
| } | ||
| } | ||
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.
Do you think we could avoid some of the optionals?
Not sure if in the callback a
nilhas a different meaning over an empty array (error maybe?).And perhaps a MediaInfo should always have a proper
type? and/or an id?Of course we can leave these improvements for another round 👍
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.
I thought that too, but we will need to check the code on the JS side and see what are the implications of sending nil or not.
Can we do this in the follow up PR?