Skip to content

Conversation

@SergioEstevao
Copy link
Contributor

@SergioEstevao SergioEstevao commented Oct 24, 2019

Beside fixing the request for import to send the correct parameters in
the callback, we are also improving the interface by replacing a tupple
for a structure to make parameters more explicit.

This can also be tested on the main app using this PR: wordpress-mobile/WordPress-iOS#12773

To test:

  • Start the demo app
  • On the image blocks check that the different sources work correctly
  • Try to copy one image from the photos app and paste inside a text block, check that an image block is added and you see an image upload simulation happening.

Update release notes:

  • If there are user facing changes, I have added an item to RELEASE-NOTES.txt.

Beside fixing the request for import to send the correct parameters in
the callback, we are also improving the interface by replacing a tupple
for a structure to make parameters more explicit.
@SergioEstevao SergioEstevao added the [Type] Bug Something isn't working label Oct 24, 2019
@SergioEstevao SergioEstevao added this to the 1.15.2 milestone Oct 24, 2019
Copy link
Contributor

@etoledom etoledom left a comment

Choose a reason for hiding this comment

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

Hey @SergioEstevao - PR looks good!

Added a few code comments, but since this is a hotfix, I don't think any of it should be worked on now.

I did find an odd behavior pasting images from the Photos app:

  • If I select a few images on a certain order, after pasting them on Gutenberg, they are added on the reversed order.

I think that if this behavior was the same before, let's keep it like this. If not, it might be good to look into it before merging?

Since this is already better than shipping the issue, we could also decide to fix the reversed order on the next release cycle, that's OK with me too.

Let me know to ✅

Comment on lines +1 to +13
public struct MediaInfo {
public let id: Int32?
public let url: String?
public let type: String?

public init(id: Int32?, url: String?, type: String?) {
self.id = id
self.url = url
self.type = type
}
}

public typealias MediaPickerDidPickMediaCallback = (_ media: [MediaInfo]?) -> Void
Copy link
Contributor

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 nil has 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 👍

Copy link
Contributor Author

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?

Comment on lines 37 to 41
let jsFormattedMedia = mediaToReturn.map { mediaInfo in
return [mediaDictKeys.IDKey: mediaInfo.id as Any,
mediaDictKeys.URLKey: mediaInfo.url as Any,
mediaDictKeys.TypeKey: mediaInfo.type as Any]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Transforming a MediaInfo instance into the Dictionary for JS might good to have it as part of the MediaInfo struct.

I was thinking about a MediaCollection type to encapsulate this kind of logic, but it's probably too much for a hotfix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I followed your suggestion and added a method to do the conversion.

Comment on lines +42 to +45
if allowMultipleSelection {
callback([jsFormattedMedia])
} else {
callback(jsFormattedMedia)
Copy link
Contributor

Choose a reason for hiding this comment

The 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!

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
It's always expecting an array where each item is an argument of the JS function.
What we can do is to cleanup the callback functions on the other side to always expect an array of media.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's do that! On another PR someday in the future 😬
It might be good to create a ticket with all these little cleanup tasks to keep track of them.

@SergioEstevao
Copy link
Contributor Author

@etoledom ready for another look.

Copy link
Contributor

@etoledom etoledom left a comment

Choose a reason for hiding this comment

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

Thank you @SergioEstevao !

It's working great now.
Tested Image, Views, Media&Text blocks with all sources and they work perfectly.

Paste images from Photos app also work as expected 🎉

@etoledom etoledom merged commit e243459 into release/1.15.2 Oct 28, 2019
@etoledom etoledom deleted the issue/fix_request_import_on_bridge branch October 28, 2019 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants