react-native-android-widget icon indicating copy to clipboard operation
react-native-android-widget copied to clipboard

Widget size issues on different Android launchers

Open sAleksovski opened this issue 2 years ago • 3 comments

We cannot render React Native views directly to the widget. What this library does is render the React Native views to an image, and then show that image in the widget. For it to look good, we need to know the exact size of the widget, so we can create an image that will fit the widget correctly.

On some Android launchers, the reported and actual size of the widget are not always the same.

Actual size Actual size (365dp x 318dp)

Reported size Reported size (365dp x 354dp)

I haven't found a reliable way to get the exact size, the current behavior is to crop the widget if the reported size is smaller.

sAleksovski avatar Aug 06 '23 15:08 sAleksovski

We have a problem the size of the widget does not come at all, it returns width:0 and height: 0. Of all the tested phones, this is observed only on Samsungs.

Debugging showed that the value 0 is returned by the method

public static int getWidgetSizeInDp(Context context, int widgetId, String key) {
 return AppWidgetManager.getInstance(context).getAppWidgetOptions(widgetId).getInt(key, 0);
 }

in java/com/reactnativeandroidwidget/RNWidgetUtil.java

Do you have ideas about what could be the problem? Looks like some sort of asynchronous code-handling error.

We've minimized the impact of this bug by setting default sizes for width and height, but even once valid non-zero values ​​are received, they are stored in the app and used in the widget.

OPavliuk-delhaize avatar Aug 23 '24 12:08 OPavliuk-delhaize

Does it received 0 only when first added?

I don't know any other way to get the widget size. You can try to request another widget update if you receive 0 sizes.

Btw I have a Samsung phone and I receive correct sizes.

sAleksovski avatar Aug 26 '24 13:08 sAleksovski

Yes, 0 comes precisely for adding the widget. But this does not always happen.

It's an interesting idea to update the widget again if the value is 0, I'll try.

Maybe you're lucky. We have this problem consistently on Samsung S24+ and Samsung Galaxy A13 Android 14

OPavliuk-delhaize avatar Aug 27 '24 07:08 OPavliuk-delhaize