All Projects → netbeast → React Native Android Widget Poc

netbeast / React Native Android Widget Poc

Licence: mit
🤖 React Native Android widgets bridged to JS, a proof of concept

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to React Native Android Widget Poc

Upgrader
Flutter package for prompting users to upgrade when there is a newer version of the app in the store.
Stars: ✭ 146 (-20.65%)
Mutual labels:  widget
Prayer Times Android
A useful Application with a set of tools needed by any muslim.
Stars: ✭ 158 (-14.13%)
Mutual labels:  widget
Jarvis2
Awesome dashboard built with Flask and Mithril
Stars: ✭ 166 (-9.78%)
Mutual labels:  widget
Scriptable
Scripts and widgets for the iOS Scriptable App
Stars: ✭ 147 (-20.11%)
Mutual labels:  widget
Graphview
Flutter GraphView is used to display data in graph structures. It can display Tree layout, Directed and Layered graph. Useful for Family Tree, Hierarchy View.
Stars: ✭ 152 (-17.39%)
Mutual labels:  widget
Ngx Dynamic Dashboard Framework
This is a JSON driven angular x based dashboard framework that is inspired by JIRA's dashboard implementation and https://github.com/raulgomis/angular-dashboard-framework
Stars: ✭ 160 (-13.04%)
Mutual labels:  widget
Elegantnumberbutton
Widget which acts as a number counter which changes its number on +/- press.
Stars: ✭ 140 (-23.91%)
Mutual labels:  widget
Qmarkdowntextedit
A C++ Qt QPlainTextEdit widget with markdown highlighting support and a lot of other extras
Stars: ✭ 182 (-1.09%)
Mutual labels:  widget
Vegalite
R ggplot2 "bindings" for Vega-Lite
Stars: ✭ 157 (-14.67%)
Mutual labels:  widget
Airpodsbattery Monitor For Mac
Simple Widget to display your AirPods battery levels from the Mac Status bar
Stars: ✭ 165 (-10.33%)
Mutual labels:  widget
Timer App
A simple Timer app for Mac
Stars: ✭ 2,047 (+1012.5%)
Mutual labels:  widget
Widgetsplayground
前端组件管理系统
Stars: ✭ 150 (-18.48%)
Mutual labels:  widget
Flutter cupertino settings
A Flutter widget to create an iOS settings-table (static TableView).
Stars: ✭ 161 (-12.5%)
Mutual labels:  widget
Mac Hanguldesktop Clock
Hangul Desktop Clock for Mac
Stars: ✭ 146 (-20.65%)
Mutual labels:  widget
Jquery Ui Contextmenu
jQuery plugin that turns a jQueryUI menu widget into a context menu.
Stars: ✭ 170 (-7.61%)
Mutual labels:  widget
Touch Bar Istats
Show CPU/GPU/MEM temperature on Touch Bar with BetterTouchTool!
Stars: ✭ 141 (-23.37%)
Mutual labels:  widget
Clendar
Clendar - universal calendar app. Written in SwiftUI. Available on App Store
Stars: ✭ 153 (-16.85%)
Mutual labels:  widget
Vue Twentytwenty
Image comparison utility
Stars: ✭ 182 (-1.09%)
Mutual labels:  widget
Flutter smart select
SmartSelect allows you to easily convert your usual form select or dropdown into dynamic page, popup dialog, or sliding bottom sheet with various choices input such as radio, checkbox, switch, chips, or even custom input. Supports single and multiple choice.
Stars: ✭ 179 (-2.72%)
Mutual labels:  widget
Yii2 Ckeditor Widget
CKEditor WYSIWYG widget for Yii2.
Stars: ✭ 163 (-11.41%)
Mutual labels:  widget

React Native Android Widget Proof Of Concept

🤖 Using React Native and having Android widgets is possible.

  1. Create buttons in Java / Android XML to triggers intents
  2. Process these intents from the Javascript side with all the tools and flexibility from react-native.

It is a bit complicated, and we developed it with little knowledge of Android in the beginnings, so I apologize if it feels bad designed. 🚧 Please help us improve the strategy / code layout with Pull Requests.

Try

git clone https://github.com/jsdario/react-native-android-widget-poc
cd react-native-android-widget-poc
npm install # or yarn install
react-native link react-native-background-timer # to avoid the main thread
react-native run-android

Demo

To build your own Android Widget, use this project to bootstrap the widget and hack upon or replicate the strategy to make it work.

How it works

It consists in several Android and React Native concepts. Please read with eskepticism, other formulas may be simpler.

  • Your React Native app, bundles all the JS, even the one corresponding to your widget and services. It is the main Activity of the Android realm.
  • A WidgetProvider is meant to render the view onto your Android desktop and also to listen for the events (button presses) that will be sent to your app. It is then, a Broadcast receiver that can process in Java different intents, before it reaches the JS side.
  • A Headless JS task is the React Native approach to an Android Service. This part will process the intents (events) coming from your WidgetProvider.
  • A custom Native Module is used to bridge the JS realm with the AppWidgetProvider.

If you take a look at the AndroidManifest.xml you can see how the Android relevant parts are declared to the system:

<manifest 
    xmlns:android="http://schemas.android.com/apk/res/android" package="com.androidwidgetpoc" android:versionCode="1" android:versionName="1.0">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
+   <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="22" />
    <application android:name=".MainApplication" android:allowBackup="true" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme">
        <activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
+        <receiver android:name="WidgetProvider">
+            <intent-filter>
+                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
+            </intent-filter>
+            <intent-filter>
+                <action android:name="com.androidwidgetpoc.CHARM_1" />
+                <action android:name="com.androidwidgetpoc.CHARM_2" />
+                <action android:name="com.androidwidgetpoc.CHARM_3" />
+            </intent-filter>
+            <meta-data android:name="android.appwidget.provider" android:resource="@xml/widgetprovider" />
+        </receiver>
+        <service android:name=".BackgroundTask" android:enabled="true" android:label="BackgroundAdd" />
    </application>
</manifest>

A step by step guide on how we got here:

  1. We prepared a Headless JS widgetTask.js to run in the as the declared service of BackgroundTask.java. We started using Android Studio heavily from this point.
  2. We created a Native Module to layout and print a Widget, so BackgroundTaskBridge.java and BackgroundTaskBridgePackage.java were born, along with the layout folder.
  3. The WidgetProvider became necessary as a proxy between the intents generated by the Widget layout (rendered thanks to the BackgroundTaskBridge) and the actual calls to the widgetTask service.
  4. Refined and serialised the messages between all the interfaces.

The hardest part? The whole JS bundle has to be running in a context for the widgetTask to run valid code. In this proof of concept app it's real quick and simple, but it can lead to huge inconsistencies if you need to pull some data from a remote or read from AsyncStorage. Be patient. Use redux or other state management to ensure the conditions you want to be running on.

Can I create widgets views using React Native instead of Java?

We haven't done this, but we belive that from this point has to be much easier, having the strategy laid down, we'd need to create Native UI Components calling methods from the RemoteView class and context instead of the View class. It is not trivial to us, though.

works with yeti

 This proof of concept is applied at Yeti Smart Home and is used in production. Some of the art is also produced at Netbeast. Follow us in Github or Twitter.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].