cooperka / react-native-snackbar

:candy: Material Design "Snackbar" component for Android and iOS.
Other
815 stars 150 forks source link

[Feature] Corner radius prop #146

Closed troZee closed 4 years ago

troZee commented 4 years ago

Hey,

Thank you for developing this libs. Currently I am using this lib in my existing project. I would like to discus with @cooperka @remstos about below feature, before I start developing new feature

Feature Request: As developer, I would like to have a ability to change border radius

Possible implementation I added patch-package to my project as follow:

+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            Drawable drawable = view.getResources().getDrawable(R.drawable.round_corner, null);
+            if (options.hasKey("backgroundColor")) {
+                drawable.setTint(options.getInt("backgroundColor"));
+            }
+            snackbarView.setBackground(drawable);
+        } else {
+            if (options.hasKey("backgroundColor")) {
+                snackbarView.setBackgroundColor(options.getInt("backgroundColor"));
+            }
         }

+++ b/node_modules/react-native-snackbar/android/src/main/res/drawable/round_corner.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape android:shape="rectangle"
+    xmlns:android="http://schemas.android.com/apk/res/android">
+    <solid android:color="#484848"/>
+    <corners android:radius="4dp"/>
+</shape>
+    self.layer.cornerRadius = 4;
+    self.layer.masksToBounds = true;
cooperka commented 4 years ago

Thanks for the feature request @troZee. I believe the corners are already somewhat rounded, do you have a screenshot of the difference before/after this code?

My main concern is that it's more work to support custom drawables like this, since they need to be tested before every new release. More code execution paths make maintenance more complex.

troZee commented 4 years ago

I believe the corners are already somewhat rounded, do you have a screenshot of the difference before/after this code?

I forgot, that we use version 1.0.2, and I added this patch package to our codebase. IDK, how about higher versions.

My main concern is that it's more work to support custom drawables like this

Totally agree with you. It would not be implemented like this due reasons, that you have provided. This should be a class, which will generate rounded corners programmatically eg https://stackoverflow.com/a/57763551/4247480 Sorry for confusing.

troZee commented 4 years ago

do you have a screenshot of the difference before/after this code?

Before Screenshot_1582719311

After Screenshot_1582719237

I see, that we also added some margins. In Before case there is no sense to add rounded corner feat.

To summarize it: Can we add margin prop ? Because then corner radius property has any sense

if you agree on that, I propose to implement above those 2 features as follow:

Snackbar.show({
  margin: {top: 0, right:0, bottom:0, left:0},
  cornerRadius: 4,
});

It would be better, if we could pass Stylesheet prop, but I don't know how to parse it on android and iOS side.

cooperka commented 4 years ago

Margins have been proposed in https://github.com/cooperka/react-native-snackbar/pull/137; that PR is blocked on feedback that needs to be addressed by the submitter. If you'd like to address my feedback and submit an updated PR for margins, feel free! Thanks.

cooperka commented 4 years ago

Closing this issue since corner radius will likely not be supported, but I will still see any replies you post.