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

[ReactToolbar] Fixed icon handling #5753

Closed
wants to merge 2 commits into from

Conversation

astuetz
Copy link

@astuetz astuetz commented Feb 4, 2016

This commit (Load assets from same folder as JSbundle (Android)) causes React Native to look for assets inside the same folder the JSBundle was loaded from and generates asset URIs containing the absolute path to the asset (e.g. /sdcard/bundle/drawable-xxhdpi/ic_back.png).

While this is fine for a normal ImageView, ToolbarAndroid/ReactToolbar currently crashes if the icons are located on the file system. This happens because when setting an icon on ReactToolbar, Fresco is only used if the icon URI contains http://or https://. For all other cases (like in this case where it starts with file://), the view tries to load the Drawable from the Android App Resources by it's name (which in this case is an absolute file-URI) and therefore causes it to crash (getDrawableResourceByName returns 0 if the Drawable was not found, then getResources().getDrawable(@DrawableRes int id) throws an Exception if the Drawable was not found).

Additionally, this PR also fixes scaling issues of Toolbar icons if they are located on the local filesystem or on a server (as the density-based scale factor / scaled size was completely ignored by ReactToolbar)

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @foghina and @crm416 to be potential reviewers.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Feb 4, 2016
@ghost
Copy link
Author

ghost commented Feb 9, 2016

any chance this can make it into 0.20.0? pinging @mkonicek @ide

@mkonicek
Copy link
Contributor

mkonicek commented Feb 9, 2016

Thanks for the PR and the explanation @astuetz! Cherry-picks into the release branch are intended for small fixes of bugs discovered during the two weeks of RC. One exception are the new Android components as adding new components won't break other code and we special-case them to get them out as quickly as possible.

While this one looks like a bugfix, it's a bit of large change to be released without testing in an RC. That said, the next RC is already next week and 0.21.0 goes out in two weeks - the releases are frequent enough so that there shouldn't be a hurry to get things into the release in general. Hope that explains it a bit.

@mkonicek
Copy link
Contributor

mkonicek commented Feb 9, 2016

I'll let @foghina review this as he worked on the image loading code in the ToolbarAndroid.

@ghost
Copy link
Author

ghost commented Feb 9, 2016

@mkonicek thanks, sounds good :)

.build();
holder.setController(controller);
} else {
callback.setDrawable(getDrawableByName(uri));
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't we reuse IconControllerListener here? Then we could get rid of SetIconSourceCallback completely.

Copy link
Author

Choose a reason for hiding this comment

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

Good point, if it's fine for you I will remove SetIconSource and rename IconControllerListener.onDrawableReady to IconControllerListener.setDrawable which sounds better for all usages then.

@facebook-github-bot
Copy link
Contributor

@astuetz updated the pull request.

@foghina
Copy link
Contributor

foghina commented Feb 10, 2016

Looks legit, thanks for the PR!

@facebook-github-bot shipit

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1524731804522669/int_phab to review.

@ghost ghost closed this in 142f8c9 Feb 10, 2016
@mkonicek
Copy link
Contributor

Thanks a lot for the review @foghina!

pglotov pushed a commit to pglotov/react-native that referenced this pull request Mar 15, 2016
Summary:
[This commit](facebook@e730a9f) (_Load assets from same folder as JSbundle (Android)_) causes React Native to look for assets inside the same folder the JSBundle was loaded from and generates asset URIs containing the absolute path to the asset (e.g. _/sdcard/bundle/drawable-xxhdpi/ic_back.png_).

While this is fine for a normal `ImageView`, `ToolbarAndroid`/`ReactToolbar` currently crashes if the icons are located on the file system. This happens because when setting an icon on `ReactToolbar`, Fresco is only used if the icon URI contains `http:// `or `https://`. For all other cases (like in this case where it starts with `file://`), the view tries to load the Drawable from the Android App Resources by it's name (which in this case is an absolute file-URI) and therefore causes it to crash (`getDrawableResourceByName` returns 0 if the Drawable was not found, then `getResources().getDrawable(DrawableRes int id)` throws an Exception if th
Closes facebook#5753

Reviewed By: svcscm

Differential Revision: D2921418

Pulled By: foghina

fb-gh-sync-id: 7a3f81b530a8c1530e98e7b592ee7e44c8f19df1
shipit-source-id: 7a3f81b530a8c1530e98e7b592ee7e44c8f19df1
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants