Skip to content

Commit 559ec64

Browse files
author
jsdario
committed
Get proof of concept working
1 parent cacd3b2 commit 559ec64

17 files changed

+38
-29
lines changed

App.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ import {
1212
View
1313
} from 'react-native';
1414

15-
const instructions = Platform.select({
16-
ios: 'Press Cmd+R to reload,\n' +
17-
'Cmd+D or shake for dev menu',
18-
android: 'Double tap R on your keyboard to reload,\n' +
19-
'Shake or press menu button for dev menu',
20-
});
21-
2215
export default class App extends Component<{}> {
2316
render() {
2417
return (
@@ -27,10 +20,11 @@ export default class App extends Component<{}> {
2720
Welcome to React Native!
2821
</Text>
2922
<Text style={styles.instructions}>
30-
To get started, edit App.js
23+
To get started, edit App.js and widgetTask.js
3124
</Text>
3225
<Text style={styles.instructions}>
33-
{instructions}
26+
Edit your native code and define the business logic in
27+
javascript
3428
</Text>
3529
</View>
3630
);

android/app/src/main/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
xmlns:android="http://schemas.android.com/apk/res/android" package="com.androidwidgetpoc" android:versionCode="1" android:versionName="1.0">
33
<uses-permission android:name="android.permission.INTERNET" />
44
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
5+
<uses-permission android:name="android.permission.WAKE_LOCK" />
56
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="22" />
67
<application android:name=".MainApplication" android:allowBackup="true" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme">
78
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:windowSoftInputMode="adjustResize">

android/app/src/main/java/com/androidwidgetpoc/MainApplication.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public boolean getUseDeveloperSupport() {
2424
protected List<ReactPackage> getPackages() {
2525
return Arrays.<ReactPackage>asList(
2626
new MainReactPackage(),
27-
new BackgroundTimerPackage(),
27+
new BackgroundTimerPackage(),
2828
new BackgroundTaskBridgePackage()
2929
);
3030
}
-20.4 KB
Binary file not shown.
-20.4 KB
Binary file not shown.
-18.7 KB
Binary file not shown.
-22.9 KB
Binary file not shown.
-27.3 KB
Binary file not shown.
-29.8 KB
Binary file not shown.
-18.3 KB
Binary file not shown.
-33 KB
Binary file not shown.
-26.9 KB
Binary file not shown.
Binary file not shown.

android/app/src/main/res/layout/appwidget.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
android:layout_height="match_parent"
3232
android:gravity="center_vertical"
3333
android:paddingLeft="5dp"
34-
android:text="Charms"
34+
android:text="React Native Widget"
3535
android:textColor="#FCFCFC"
3636
android:textSize="14sp" />
3737

@@ -51,6 +51,6 @@
5151
android:layout_height="match_parent"
5252
android:textColor="#FCFCFC"
5353
android:gravity="center"
54-
android:text="Configure your charms" />
54+
android:text="Placeholder text" />
5555

5656
</LinearLayout>

index.android.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { AppRegistry } from 'react-native';
2+
import App from './App';
3+
import widgetTask from './widgetTask';
4+
5+
AppRegistry.registerHeadlessTask('widgetTask', () => widgetTask);
6+
AppRegistry.registerComponent('androidWidgetPoc', () => App);
7+

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AppRegistry } from 'react-native';
22
import App from './App';
3-
import widgetTask from './widgetTask';
3+
import WidgetTask from './widgetTask';
44

55
AppRegistry.registerComponent('androidWidgetPoc', () => App);
6-
AppRegistry.registerHeadlessTask('widgetTask', () => widgetTask);
6+
AppRegistry.registerHeadlessTask('WidgetTask', () => WidgetTask);
77

widgetTask.js

+22-15
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,40 @@
33
*/
44

55
import { NativeModules, ToastAndroid } from 'react-native'
6+
import bgTimer from 'react-native-background-timer'
7+
68
const { BackgroundTaskBridge } = NativeModules
79

10+
const charms = [
11+
{
12+
id: 'uuid1',
13+
name: 'First',
14+
cover: 'goodmorning',
15+
},
16+
{
17+
id: 'uuid2',
18+
name: 'Second',
19+
cover: 'night',
20+
}
21+
]
22+
823
type TaskInfo = {
924
id: string,
1025
}
1126
export default async function widgetTask (taskData: TaskInfo) {
1227
const {id} = taskData || {}
13-
console.log('Running widget task')
14-
synchronizeWidget()
15-
triggerCharm(id)
28+
bgTimer.setTimeout(() => {
29+
synchronizeWidget()
30+
triggerCharm(id)
31+
}, 0)
1632
}
1733

1834
export function synchronizeWidget () {
35+
ToastAndroid.show(`Initializing ...`, ToastAndroid.SHORT);
1936
BackgroundTaskBridge.initializeWidgetBridge(charms)
2037
}
2138

2239
function triggerCharm (id) {
40+
if (!id) return
2341
ToastAndroid.show(`Triggering ${id}...`, ToastAndroid.SHORT);
24-
}
25-
26-
const charms = {
27-
uuid1: {
28-
id: 'uuid1',
29-
name: 'First',
30-
},
31-
uuid2: {
32-
id: 'uuid2',
33-
name: 'Second',
34-
}
35-
}
42+
}

0 commit comments

Comments
 (0)