@haykmkrtich/react-native-patriot-native 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+
2
+ apply plugin: 'com.android.library'
3
+ apply plugin: 'com.facebook.react'
4
+
5
+ android {
6
+ compileSdkVersion 34
7
+
8
+ defaultConfig {
9
+ minSdkVersion 21
10
+ targetSdkVersion 34
11
+ }
12
+
13
+ compileOptions {
14
+ sourceCompatibility JavaVersion.VERSION_11
15
+ targetCompatibility JavaVersion.VERSION_11
16
+ }
17
+ }
18
+
19
+ dependencies {
20
+ implementation 'androidx.annotation:annotation:1.3.0'
21
+ implementation 'com.google.android.gms:play-services-wearable:18.1.0'
22
+ implementation 'androidx.wear:wear-remote-interactions:1.0.0'
23
+ }
@@ -0,0 +1,74 @@
1
+
2
+ package com.patriotnative;
3
+
4
+ import android.content.Intent;
5
+ import android.net.Uri;
6
+ import android.os.Handler;
7
+ import android.os.Looper;
8
+ import android.widget.Toast;
9
+
10
+ import androidx.annotation.NonNull;
11
+ import androidx.wear.remote.interactions.RemoteActivityHelper;
12
+
13
+ import com.facebook.react.bridge.ReactApplicationContext;
14
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
15
+ import com.facebook.react.bridge.ReactMethod;
16
+ import com.facebook.react.bridge.Promise;
17
+
18
+ import com.google.android.gms.tasks.Task;
19
+ import com.google.android.gms.tasks.Tasks;
20
+ import com.google.android.gms.wearable.Node;
21
+ import com.google.android.gms.wearable.Wearable;
22
+
23
+ import java.util.List;
24
+ import java.util.concurrent.Executors;
25
+
26
+ public class PatriotNativeModule extends ReactContextBaseJavaModule {
27
+ private final ReactApplicationContext reactContext;
28
+
29
+ public PatriotNativeModule(ReactApplicationContext context) {
30
+ super(context);
31
+ this.reactContext = context;
32
+ }
33
+
34
+ @NonNull
35
+ @Override
36
+ public String getName() {
37
+ return "PatriotNative";
38
+ }
39
+
40
+ @ReactMethod
41
+ public void installWatchface(String packageName, Promise promise) {
42
+ new Thread(() -> {
43
+ try {
44
+ Task<List<Node>> nodeListTask = Wearable.getNodeClient(reactContext).getConnectedNodes();
45
+ List<Node> nodes = Tasks.await(nodeListTask);
46
+
47
+ if (nodes.isEmpty()) {
48
+ showToast("Watch not connected");
49
+ promise.reject("NO_NODES", "No connected WearOS device found.");
50
+ return;
51
+ }
52
+
53
+ for (Node node : nodes) {
54
+ Intent intent = new Intent(Intent.ACTION_VIEW);
55
+ intent.addCategory(Intent.CATEGORY_BROWSABLE);
56
+ intent.setData(Uri.parse("market://details?id=" + packageName));
57
+
58
+ RemoteActivityHelper helper = new RemoteActivityHelper(reactContext, Executors.newSingleThreadExecutor());
59
+ helper.startRemoteActivity(intent, node.getId());
60
+ }
61
+
62
+ showToast("Check your watch");
63
+ promise.resolve(null);
64
+ } catch (Exception e) {
65
+ promise.reject("INSTALL_FAILED", e.getMessage());
66
+ }
67
+ }).start();
68
+ }
69
+
70
+ private void showToast(String msg) {
71
+ new Handler(Looper.getMainLooper()).post(() ->
72
+ Toast.makeText(reactContext, msg, Toast.LENGTH_SHORT).show());
73
+ }
74
+ }
@@ -0,0 +1,25 @@
1
+
2
+ package com.patriotnative;
3
+
4
+ import com.facebook.react.ReactPackage;
5
+ import com.facebook.react.bridge.NativeModule;
6
+ import com.facebook.react.bridge.ReactApplicationContext;
7
+ import com.facebook.react.uimanager.ViewManager;
8
+
9
+ import java.util.ArrayList;
10
+ import java.util.Collections;
11
+ import java.util.List;
12
+
13
+ public class PatriotNativePackage implements ReactPackage {
14
+ @Override
15
+ public List<NativeModule> createNativeModules(ReactApplicationContext context) {
16
+ List<NativeModule> modules = new ArrayList<>();
17
+ modules.add(new PatriotNativeModule(context));
18
+ return modules;
19
+ }
20
+
21
+ @Override
22
+ public List<ViewManager> createViewManagers(ReactApplicationContext context) {
23
+ return Collections.emptyList();
24
+ }
25
+ }
package/index.ts ADDED
@@ -0,0 +1,12 @@
1
+
2
+ import { NativeModules } from 'react-native';
3
+
4
+ type PatriotNativeType = {
5
+ installWatchface(packageName: string): Promise<void>;
6
+ };
7
+
8
+ const { PatriotNative } = NativeModules as { PatriotNative: PatriotNativeType };
9
+
10
+ export function installWatchface(packageName: string): Promise<void> {
11
+ return PatriotNative.installWatchface(packageName);
12
+ }
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@haykmkrtich/react-native-patriot-native",
3
+ "version": "1.0.0",
4
+ "main": "index.ts",
5
+ "files": [
6
+ "index.ts",
7
+ "android/"
8
+ ],
9
+ "keywords": ["react-native", "wearos", "watchface"],
10
+ "author": "Hayk Mkrtich",
11
+ "license": "MIT",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/yourusername/react-native-patriot-native"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ }
19
+ }