sAleksovski / react-native-android-widget

Build Android Widgets with React Native
https://sAleksovski.github.io/react-native-android-widget/
MIT License
591 stars 22 forks source link

Request: Add TextClock #67

Closed huttonjd closed 7 months ago

huttonjd commented 8 months ago

I ready do appreciate all the work you have done in putting this together. I am needing Android TextClock primitive. Do you have plans to add it? If not, I will fork your repo and add it. I can share fork once I add it

sAleksovski commented 8 months ago

Hi,

Thanks.

I'm not sure if it can be implemented efficiently. Current primitives don't render to the Android widget primitives, since we have to use RemotableViewMethod methods, and they are pretty limited in comparison with xml view attributes. This library renders the primitives to an image, and then shows the image in the widget, with absolutely positioned buttons for handling clicks.

TextClock would need to use the actual android component, since it should update every minute/second, depending on the format. We cannot configure everything on the TextClock using RemotableViewMethods (for example we cannot change the font).

Feel free to try to add it, and if you are successful we can port it here.

huttonjd commented 8 months ago

I agree - I will see what i can do and let you know!!

sAleksovski commented 7 months ago

Closing since this is not planned.

huttonjd commented 7 months ago

BTW: I got TextClock added its here https://www.npmjs.com/package/my-react-native-android-widget I added 12 & 24 formats and all updates Font (type/size) work fine, but still working on why TextClock is not updating the TextClock. It appears that the onAttachedToWindow is not firing (that is the code that registers the time receiver). I am still working on it :)

sAleksovski commented 7 months ago

You didn't share the full changes, but from I could see in https://www.npmjs.com/package/my-react-native-android-widget?activeTab=code you are adding the TextClock like the other primitives, which just grabs an image of it at the time when the widget is updated. It will never call onAttachedToWindow since TextClock is never actually added to the widget.

In order for it to be shown you would need to implement something similar to how ListWidget is implemented.