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

Font Family prop & RTL support for android #117

Closed
wants to merge 16 commits into from

Conversation

alijamaliz
Copy link
Contributor

No description provided.

Copy link
Owner

@cooperka cooperka left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this change @alijamaliz. I left some general feedback, but overall happy with it.

According to and old comment #62 (comment) RTL was previously working; I never tested it myself, but for posterity can you please include a screenshot of the snackbar before and after this change?

I appreciate the good work!

package.json Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated
@@ -65,6 +67,8 @@ Snackbar.show({
| `action` | `object` (described below) | `undefined` (no button) | Optional config for the action button (described below). |
| `backgroundColor` | `string` or `style` | `undefined` (natively renders as black) | The background color for the whole Snackbar. |
| `color` | `string` or `style` | `undefined` (natively renders as white) | The text color for the title. |
| `fontFamily` | `string` | `undefined` (use native default font) | Font family of snackbar title and action (See **Font support for android** section below). |
| `RTL` | `boolean` | `false` | Direction of the snackbar (See **RTL support for android** section below). |
Copy link
Owner

Choose a reason for hiding this comment

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

Personal convention preference: Please use lowercase rtl for the prop name (uppercase is still fine for text comments, of course)

Copy link
Owner

Choose a reason for hiding this comment

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

Can this be detected automatically? Seems like there should be some app-wide setting that determines whether it's RTL or not, rather than passing a prop 🤔

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 replaced all RTLs with rtl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And about the second comment, it is a good idea.
I did little search and I found many approaches to determine that.
It can be implemented later...

@@ -118,6 +125,12 @@ public void onClick(View v) {
ReadableMap actionDetails = options.getMap("action");
snackbar.setAction(actionDetails.getString("title"), onClickListener);
snackbar.setActionTextColor(actionDetails.getInt("color"));

if (fontFamily != null) {
Typeface font = Typeface.createFromAsset(this.context.getAssets(), "fonts/" + fontFamily + ".ttf");
Copy link
Owner

Choose a reason for hiding this comment

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

Is this directory conventional? What about res/font/ for example?

}

if (fontFamily != null) {
Typeface font = Typeface.createFromAsset(this.context.getAssets(), "fonts/" + fontFamily + ".ttf");
Copy link
Owner

Choose a reason for hiding this comment

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

Since this is done twice let's make it a variable to cache it.

private static final String REACT_NAME = "RNSnackbar";

private List<Snackbar> mActiveSnackbars = new ArrayList<>();

public SnackbarModule(ReactApplicationContext reactContext) {
super(reactContext);
this.context = reactContext.getApplicationContext();
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of saving a member var that could be nullified when the app goes away, let's just use a local Context context = getReactApplicationContext().getApplicationContext() below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I don't now much about android. so I can't understand where should I put this line.

@guvenakcoban
Copy link

Is there any update on that pr? @alijamaliz @cooperka. I just want to use a custom font family.

@cooperka
Copy link
Owner

Hi @guvenakcoban, I haven't yet had time to fully test this using the new props and RTL language settings, or to document screenshots before/after. I may have time next week around the holidays.

In the meantime, you are welcome to fork this library and merge the PR on your fork so you can use it right away.

@cooperka
Copy link
Owner

fontFamily support has been cherry-picked to master in 3994de3. Thank you again @alijamaliz. Demo from the example app:

Screen Shot 2020-01-20 at 18 15 54

I will leave this PR open until RTL changes are also in (I'm planning to cherry-pick those as well, but no guarantees).

@cooperka
Copy link
Owner

And rtl support has been cherry-picked to master in f89d3e8. Demo from the example app:

Screen Shot 2020-01-20 at 18 42 16

Source:

Screen Shot 2020-01-20 at 18 43 06

Closing as these changes are now merged.

Released in v2.2.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants