react-native-kookit 0.1.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.
Files changed (44) hide show
  1. package/.eslintrc.js +5 -0
  2. package/README.md +35 -0
  3. package/android/build.gradle +43 -0
  4. package/android/src/main/AndroidManifest.xml +2 -0
  5. package/android/src/main/java/expo/modules/kookit/ReactNativeKookitModule.kt +114 -0
  6. package/android/src/main/java/expo/modules/kookit/ReactNativeKookitView.kt +30 -0
  7. package/android/src/main/java/expo/modules/kookit/VolumeKeyInterceptActivity.kt +67 -0
  8. package/build/ReactNativeKookit.types.d.ts +22 -0
  9. package/build/ReactNativeKookit.types.d.ts.map +1 -0
  10. package/build/ReactNativeKookit.types.js +2 -0
  11. package/build/ReactNativeKookit.types.js.map +1 -0
  12. package/build/ReactNativeKookitModule.d.ts +12 -0
  13. package/build/ReactNativeKookitModule.d.ts.map +1 -0
  14. package/build/ReactNativeKookitModule.js +4 -0
  15. package/build/ReactNativeKookitModule.js.map +1 -0
  16. package/build/ReactNativeKookitModule.web.d.ts +13 -0
  17. package/build/ReactNativeKookitModule.web.d.ts.map +1 -0
  18. package/build/ReactNativeKookitModule.web.js +40 -0
  19. package/build/ReactNativeKookitModule.web.js.map +1 -0
  20. package/build/ReactNativeKookitView.d.ts +4 -0
  21. package/build/ReactNativeKookitView.d.ts.map +1 -0
  22. package/build/ReactNativeKookitView.js +7 -0
  23. package/build/ReactNativeKookitView.js.map +1 -0
  24. package/build/ReactNativeKookitView.web.d.ts +4 -0
  25. package/build/ReactNativeKookitView.web.d.ts.map +1 -0
  26. package/build/ReactNativeKookitView.web.js +7 -0
  27. package/build/ReactNativeKookitView.web.js.map +1 -0
  28. package/build/index.d.ts +4 -0
  29. package/build/index.d.ts.map +1 -0
  30. package/build/index.js +6 -0
  31. package/build/index.js.map +1 -0
  32. package/expo-module.config.json +9 -0
  33. package/ios/ReactNativeKookit.podspec +29 -0
  34. package/ios/ReactNativeKookitModule.swift +156 -0
  35. package/ios/ReactNativeKookitView.swift +38 -0
  36. package/package.json +43 -0
  37. package/src/ReactNativeKookit.types.ts +24 -0
  38. package/src/ReactNativeKookitModule.ts +16 -0
  39. package/src/ReactNativeKookitModule.web.ts +48 -0
  40. package/src/ReactNativeKookitView.tsx +11 -0
  41. package/src/ReactNativeKookitView.web.tsx +15 -0
  42. package/src/index.ts +5 -0
  43. package/test-volume-keys.sh +25 -0
  44. package/tsconfig.json +9 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ root: true,
3
+ extends: ['universe/native', 'universe/web'],
4
+ ignorePatterns: ['build'],
5
+ };
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # react-native-kookit
2
+
3
+ My new module
4
+
5
+ # API documentation
6
+
7
+ - [Documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/react-native-kookit/)
8
+ - [Documentation for the main branch](https://docs.expo.dev/versions/unversioned/sdk/react-native-kookit/)
9
+
10
+ # Installation in managed Expo projects
11
+
12
+ For [managed](https://docs.expo.dev/archive/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](#api-documentation). If you follow the link and there is no documentation available then this library is not yet usable within managed projects — it is likely to be included in an upcoming Expo SDK release.
13
+
14
+ # Installation in bare React Native projects
15
+
16
+ For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
17
+
18
+ ### Add the package to your npm dependencies
19
+
20
+ ```
21
+ npm install react-native-kookit
22
+ ```
23
+
24
+ ### Configure for Android
25
+
26
+
27
+
28
+
29
+ ### Configure for iOS
30
+
31
+ Run `npx pod-install` after installing the npm package.
32
+
33
+ # Contributing
34
+
35
+ Contributions are very welcome! Please refer to guidelines described in the [contributing guide]( https://github.com/expo/expo#contributing).
@@ -0,0 +1,43 @@
1
+ apply plugin: 'com.android.library'
2
+
3
+ group = 'expo.modules.kookit'
4
+ version = '0.1.0'
5
+
6
+ def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
7
+ apply from: expoModulesCorePlugin
8
+ applyKotlinExpoModulesCorePlugin()
9
+ useCoreDependencies()
10
+ useExpoPublishing()
11
+
12
+ // If you want to use the managed Android SDK versions from expo-modules-core, set this to true.
13
+ // The Android SDK versions will be bumped from time to time in SDK releases and may introduce breaking changes in your module code.
14
+ // Most of the time, you may like to manage the Android SDK versions yourself.
15
+ def useManagedAndroidSdkVersions = false
16
+ if (useManagedAndroidSdkVersions) {
17
+ useDefaultAndroidSdkVersions()
18
+ } else {
19
+ buildscript {
20
+ // Simple helper that allows the root project to override versions declared by this library.
21
+ ext.safeExtGet = { prop, fallback ->
22
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
23
+ }
24
+ }
25
+ project.android {
26
+ compileSdkVersion safeExtGet("compileSdkVersion", 34)
27
+ defaultConfig {
28
+ minSdkVersion safeExtGet("minSdkVersion", 21)
29
+ targetSdkVersion safeExtGet("targetSdkVersion", 34)
30
+ }
31
+ }
32
+ }
33
+
34
+ android {
35
+ namespace "expo.modules.kookit"
36
+ defaultConfig {
37
+ versionCode 1
38
+ versionName "0.1.0"
39
+ }
40
+ lintOptions {
41
+ abortOnError false
42
+ }
43
+ }
@@ -0,0 +1,2 @@
1
+ <manifest>
2
+ </manifest>
@@ -0,0 +1,114 @@
1
+ package expo.modules.kookit
2
+
3
+ import expo.modules.kotlin.modules.Module
4
+ import expo.modules.kotlin.modules.ModuleDefinition
5
+ import android.app.Activity
6
+ import android.content.Context
7
+ import android.media.AudioManager
8
+ import android.view.KeyEvent
9
+ import expo.modules.kotlin.AppContext
10
+ import expo.modules.kotlin.exception.Exceptions
11
+ import java.net.URL
12
+
13
+ class ReactNativeKookitModule : Module() {
14
+ private var isVolumeListenerEnabled = false
15
+ private var audioManager: AudioManager? = null
16
+ private var originalStreamVolume: Int = 0
17
+
18
+ // Each module class must implement the definition function. The definition consists of components
19
+ // that describes the module's functionality and behavior.
20
+ // See https://docs.expo.dev/modules/module-api for more details about available components.
21
+ override fun definition() = ModuleDefinition {
22
+ // Sets the name of the module that JavaScript code will use to refer to the module. Takes a string as an argument.
23
+ // Can be inferred from module's class name, but it's recommended to set it explicitly for clarity.
24
+ // The module will be accessible from `requireNativeModule('ReactNativeKookit')` in JavaScript.
25
+ Name("ReactNativeKookit")
26
+
27
+ // Sets constant properties on the module. Can take a dictionary or a closure that returns a dictionary.
28
+ Constants(
29
+ "PI" to Math.PI
30
+ )
31
+
32
+ // Defines event names that the module can send to JavaScript.
33
+ Events("onChange", "onVolumeButtonPressed")
34
+
35
+ // Function to enable volume key interception
36
+ Function("enableVolumeKeyInterception") {
37
+ enableVolumeKeyInterception()
38
+ }
39
+
40
+ // Function to disable volume key interception
41
+ Function("disableVolumeKeyInterception") {
42
+ disableVolumeKeyInterception()
43
+ }
44
+
45
+ // Defines a JavaScript synchronous function that runs the native code on the JavaScript thread.
46
+ Function("hello") {
47
+ "Hello world! !👋"
48
+ }
49
+
50
+ // Defines a JavaScript function that always returns a Promise and whose native code
51
+ // is by default dispatched on the different thread than the JavaScript runtime runs on.
52
+ AsyncFunction("setValueAsync") { value: String ->
53
+ // Send an event to JavaScript.
54
+ sendEvent("onChange", mapOf(
55
+ "value" to value
56
+ ))
57
+ }
58
+
59
+ // Enables the module to be used as a native view. Definition components that are accepted as part of
60
+ // the view definition: Prop, Events.
61
+ View(ReactNativeKookitView::class) {
62
+ // Defines a setter for the `url` prop.
63
+ Prop("url") { view: ReactNativeKookitView, url: URL ->
64
+ view.webView.loadUrl(url.toString())
65
+ }
66
+ // Defines an event that the view can send to JavaScript.
67
+ Events("onLoad")
68
+ }
69
+ }
70
+
71
+ private fun enableVolumeKeyInterception() {
72
+ try {
73
+ val context = appContext.reactContext ?: throw Exceptions.ReactContextLost()
74
+ audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
75
+
76
+ // Store original volume to restore later if needed
77
+ originalStreamVolume = audioManager?.getStreamVolume(AudioManager.STREAM_MUSIC) ?: 0
78
+
79
+ isVolumeListenerEnabled = true
80
+
81
+ // Install key event interceptor at the application level
82
+ val activity = appContext.currentActivity
83
+ activity?.let { act ->
84
+ VolumeKeyInterceptor.install(act) { keyCode ->
85
+ val keyType = when (keyCode) {
86
+ KeyEvent.KEYCODE_VOLUME_UP -> "up"
87
+ KeyEvent.KEYCODE_VOLUME_DOWN -> "down"
88
+ else -> "unknown"
89
+ }
90
+ sendEvent("onVolumeButtonPressed", mapOf("key" to keyType))
91
+ }
92
+ }
93
+
94
+ } catch (e: Exception) {
95
+ throw Exceptions.ReactContextLost()
96
+ }
97
+ }
98
+
99
+ private fun disableVolumeKeyInterception() {
100
+ try {
101
+ isVolumeListenerEnabled = false
102
+
103
+ val activity = appContext.currentActivity
104
+ activity?.let { act ->
105
+ VolumeKeyInterceptor.uninstall(act)
106
+ }
107
+
108
+ audioManager = null
109
+
110
+ } catch (e: Exception) {
111
+ // Context might be lost, ignore
112
+ }
113
+ }
114
+ }
@@ -0,0 +1,30 @@
1
+ package expo.modules.kookit
2
+
3
+ import android.content.Context
4
+ import android.webkit.WebView
5
+ import android.webkit.WebViewClient
6
+ import expo.modules.kotlin.AppContext
7
+ import expo.modules.kotlin.viewevent.EventDispatcher
8
+ import expo.modules.kotlin.views.ExpoView
9
+
10
+ class ReactNativeKookitView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
11
+ // Creates and initializes an event dispatcher for the `onLoad` event.
12
+ // The name of the event is inferred from the value and needs to match the event name defined in the module.
13
+ private val onLoad by EventDispatcher()
14
+
15
+ // Defines a WebView that will be used as the root subview.
16
+ internal val webView = WebView(context).apply {
17
+ layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
18
+ webViewClient = object : WebViewClient() {
19
+ override fun onPageFinished(view: WebView, url: String) {
20
+ // Sends an event to JavaScript. Triggers a callback defined on the view component in JavaScript.
21
+ onLoad(mapOf("url" to url))
22
+ }
23
+ }
24
+ }
25
+
26
+ init {
27
+ // Adds the WebView to the view hierarchy.
28
+ addView(webView)
29
+ }
30
+ }
@@ -0,0 +1,67 @@
1
+ package expo.modules.kookit
2
+
3
+ import android.app.Activity
4
+ import android.view.KeyEvent
5
+ import java.lang.ref.WeakReference
6
+
7
+ object VolumeKeyInterceptor {
8
+ private var activityRef: WeakReference<Activity>? = null
9
+ private var keyListener: ((Int) -> Unit)? = null
10
+ private var isEnabled = false
11
+
12
+ fun install(activity: Activity, listener: (Int) -> Unit) {
13
+ activityRef = WeakReference(activity)
14
+ keyListener = listener
15
+ isEnabled = true
16
+
17
+ // Override the activity's dispatchKeyEvent method
18
+ if (activity is VolumeKeyInterceptActivity) {
19
+ activity.setVolumeKeyInterceptEnabled(true)
20
+ activity.setVolumeKeyListener(listener)
21
+ } else {
22
+ // Try to use reflection or other methods if the activity doesn't implement the interface
23
+ installFallback(activity, listener)
24
+ }
25
+ }
26
+
27
+ fun uninstall(activity: Activity) {
28
+ isEnabled = false
29
+ keyListener = null
30
+
31
+ if (activity is VolumeKeyInterceptActivity) {
32
+ activity.setVolumeKeyInterceptEnabled(false)
33
+ activity.setVolumeKeyListener(null)
34
+ }
35
+
36
+ activityRef = null
37
+ }
38
+
39
+ private fun installFallback(activity: Activity, listener: (Int) -> Unit) {
40
+ // For activities that don't implement VolumeKeyInterceptActivity
41
+ // We'll need the developer to manually add the key handling
42
+ }
43
+
44
+ fun handleKeyEvent(event: KeyEvent): Boolean {
45
+ if (!isEnabled) return false
46
+
47
+ return when (event.keyCode) {
48
+ KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_VOLUME_DOWN -> {
49
+ if (event.action == KeyEvent.ACTION_DOWN) {
50
+ keyListener?.invoke(event.keyCode)
51
+ }
52
+ true // Consume the event to prevent system volume change and HUD
53
+ }
54
+ else -> false
55
+ }
56
+ }
57
+ }
58
+
59
+ interface VolumeKeyInterceptActivity {
60
+ fun setVolumeKeyListener(listener: ((Int) -> Unit)?)
61
+ fun setVolumeKeyInterceptEnabled(enabled: Boolean)
62
+ }
63
+
64
+ // Extension function to help activities implement volume key interception
65
+ fun Activity.handleVolumeKeyEvent(event: KeyEvent): Boolean {
66
+ return VolumeKeyInterceptor.handleKeyEvent(event)
67
+ }
@@ -0,0 +1,22 @@
1
+ import type { StyleProp, ViewStyle } from "react-native";
2
+ export type OnLoadEventPayload = {
3
+ url: string;
4
+ };
5
+ export type VolumeKeyEventPayload = {
6
+ key: "up" | "down";
7
+ };
8
+ export type ReactNativeKookitModuleEvents = {
9
+ onChange: (params: ChangeEventPayload) => void;
10
+ onVolumeButtonPressed: (params: VolumeKeyEventPayload) => void;
11
+ };
12
+ export type ChangeEventPayload = {
13
+ value: string;
14
+ };
15
+ export type ReactNativeKookitViewProps = {
16
+ url: string;
17
+ onLoad: (event: {
18
+ nativeEvent: OnLoadEventPayload;
19
+ }) => void;
20
+ style?: StyleProp<ViewStyle>;
21
+ };
22
+ //# sourceMappingURL=ReactNativeKookit.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeKookit.types.d.ts","sourceRoot":"","sources":["../src/ReactNativeKookit.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,GAAG,EAAE,IAAI,GAAG,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,QAAQ,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC/C,qBAAqB,EAAE,CAAC,MAAM,EAAE,qBAAqB,KAAK,IAAI,CAAC;CAChE,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE,kBAAkB,CAAA;KAAE,KAAK,IAAI,CAAC;IAC7D,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC9B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ReactNativeKookit.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeKookit.types.js","sourceRoot":"","sources":["../src/ReactNativeKookit.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { StyleProp, ViewStyle } from \"react-native\";\n\nexport type OnLoadEventPayload = {\n url: string;\n};\n\nexport type VolumeKeyEventPayload = {\n key: \"up\" | \"down\";\n};\n\nexport type ReactNativeKookitModuleEvents = {\n onChange: (params: ChangeEventPayload) => void;\n onVolumeButtonPressed: (params: VolumeKeyEventPayload) => void;\n};\n\nexport type ChangeEventPayload = {\n value: string;\n};\n\nexport type ReactNativeKookitViewProps = {\n url: string;\n onLoad: (event: { nativeEvent: OnLoadEventPayload }) => void;\n style?: StyleProp<ViewStyle>;\n};\n"]}
@@ -0,0 +1,12 @@
1
+ import { NativeModule } from "expo";
2
+ import { ReactNativeKookitModuleEvents } from "./ReactNativeKookit.types";
3
+ declare class ReactNativeKookitModule extends NativeModule<ReactNativeKookitModuleEvents> {
4
+ PI: number;
5
+ hello(): string;
6
+ setValueAsync(value: string): Promise<void>;
7
+ enableVolumeKeyInterception(): void;
8
+ disableVolumeKeyInterception(): void;
9
+ }
10
+ declare const _default: ReactNativeKookitModule;
11
+ export default _default;
12
+ //# sourceMappingURL=ReactNativeKookitModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeKookitModule.d.ts","sourceRoot":"","sources":["../src/ReactNativeKookitModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAuB,MAAM,MAAM,CAAC;AAEzD,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,OAAO,OAAO,uBAAwB,SAAQ,YAAY,CAAC,6BAA6B,CAAC;IACvF,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,IAAI,MAAM;IACf,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3C,2BAA2B,IAAI,IAAI;IACnC,4BAA4B,IAAI,IAAI;CACrC;;AAGD,wBAEE"}
@@ -0,0 +1,4 @@
1
+ import { requireNativeModule } from "expo";
2
+ // This call loads the native module object from the JSI.
3
+ export default requireNativeModule("ReactNativeKookit");
4
+ //# sourceMappingURL=ReactNativeKookitModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeKookitModule.js","sourceRoot":"","sources":["../src/ReactNativeKookitModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAYzD,yDAAyD;AACzD,eAAe,mBAAmB,CAChC,mBAAmB,CACpB,CAAC","sourcesContent":["import { NativeModule, requireNativeModule } from \"expo\";\n\nimport { ReactNativeKookitModuleEvents } from \"./ReactNativeKookit.types\";\n\ndeclare class ReactNativeKookitModule extends NativeModule<ReactNativeKookitModuleEvents> {\n PI: number;\n hello(): string;\n setValueAsync(value: string): Promise<void>;\n enableVolumeKeyInterception(): void;\n disableVolumeKeyInterception(): void;\n}\n\n// This call loads the native module object from the JSI.\nexport default requireNativeModule<ReactNativeKookitModule>(\n \"ReactNativeKookit\"\n);\n"]}
@@ -0,0 +1,13 @@
1
+ import { NativeModule } from "expo";
2
+ import { ReactNativeKookitModuleEvents } from "./ReactNativeKookit.types";
3
+ declare class ReactNativeKookitModule extends NativeModule<ReactNativeKookitModuleEvents> {
4
+ PI: number;
5
+ setValueAsync(value: string): Promise<void>;
6
+ hello(): string;
7
+ enableVolumeKeyInterception(): void;
8
+ disableVolumeKeyInterception(): void;
9
+ private handleKeyDown;
10
+ }
11
+ declare const _default: typeof ReactNativeKookitModule;
12
+ export default _default;
13
+ //# sourceMappingURL=ReactNativeKookitModule.web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeKookitModule.web.d.ts","sourceRoot":"","sources":["../src/ReactNativeKookitModule.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,YAAY,EAAE,MAAM,MAAM,CAAC;AAEvD,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,cAAM,uBAAwB,SAAQ,YAAY,CAAC,6BAA6B,CAAC;IAC/E,EAAE,SAAW;IACP,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAGjD,KAAK;IAGL,2BAA2B;IAO3B,4BAA4B;IAO5B,OAAO,CAAC,aAAa;CAgBtB;;AAED,wBAGE"}
@@ -0,0 +1,40 @@
1
+ import { registerWebModule, NativeModule } from "expo";
2
+ class ReactNativeKookitModule extends NativeModule {
3
+ PI = Math.PI;
4
+ async setValueAsync(value) {
5
+ this.emit("onChange", { value });
6
+ }
7
+ hello() {
8
+ return "Hello world! 👋";
9
+ }
10
+ enableVolumeKeyInterception() {
11
+ // Web implementation - listen for keyboard events
12
+ if (typeof window !== "undefined") {
13
+ this.handleKeyDown = this.handleKeyDown.bind(this);
14
+ window.addEventListener("keydown", this.handleKeyDown);
15
+ }
16
+ }
17
+ disableVolumeKeyInterception() {
18
+ // Web implementation - remove keyboard event listeners
19
+ if (typeof window !== "undefined" && this.handleKeyDown) {
20
+ window.removeEventListener("keydown", this.handleKeyDown);
21
+ }
22
+ }
23
+ handleKeyDown(event) {
24
+ // On web, we can simulate volume key detection using specific keys
25
+ // This is a fallback since web doesn't have direct access to volume keys
26
+ let keyType = null;
27
+ if (event.code === "ArrowUp" && event.altKey) {
28
+ keyType = "up";
29
+ }
30
+ else if (event.code === "ArrowDown" && event.altKey) {
31
+ keyType = "down";
32
+ }
33
+ if (keyType) {
34
+ event.preventDefault();
35
+ this.emit("onVolumeButtonPressed", { key: keyType });
36
+ }
37
+ }
38
+ }
39
+ export default registerWebModule(ReactNativeKookitModule, "ReactNativeKookitModule");
40
+ //# sourceMappingURL=ReactNativeKookitModule.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeKookitModule.web.js","sourceRoot":"","sources":["../src/ReactNativeKookitModule.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAIvD,MAAM,uBAAwB,SAAQ,YAA2C;IAC/E,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;IACb,KAAK,CAAC,aAAa,CAAC,KAAa;QAC/B,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IACnC,CAAC;IACD,KAAK;QACH,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IACD,2BAA2B;QACzB,kDAAkD;QAClD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAClC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnD,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IACD,4BAA4B;QAC1B,uDAAuD;QACvD,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACxD,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;IAEO,aAAa,CAAC,KAAoB;QACxC,mEAAmE;QACnE,yEAAyE;QACzE,IAAI,OAAO,GAAyB,IAAI,CAAC;QAEzC,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YAC7C,OAAO,GAAG,IAAI,CAAC;QACjB,CAAC;aAAM,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YACtD,OAAO,GAAG,MAAM,CAAC;QACnB,CAAC;QAED,IAAI,OAAO,EAAE,CAAC;YACZ,KAAK,CAAC,cAAc,EAAE,CAAC;YACvB,IAAI,CAAC,IAAI,CAAC,uBAAuB,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;CACF;AAED,eAAe,iBAAiB,CAC9B,uBAAuB,EACvB,yBAAyB,CAC1B,CAAC","sourcesContent":["import { registerWebModule, NativeModule } from \"expo\";\n\nimport { ReactNativeKookitModuleEvents } from \"./ReactNativeKookit.types\";\n\nclass ReactNativeKookitModule extends NativeModule<ReactNativeKookitModuleEvents> {\n PI = Math.PI;\n async setValueAsync(value: string): Promise<void> {\n this.emit(\"onChange\", { value });\n }\n hello() {\n return \"Hello world! 👋\";\n }\n enableVolumeKeyInterception() {\n // Web implementation - listen for keyboard events\n if (typeof window !== \"undefined\") {\n this.handleKeyDown = this.handleKeyDown.bind(this);\n window.addEventListener(\"keydown\", this.handleKeyDown);\n }\n }\n disableVolumeKeyInterception() {\n // Web implementation - remove keyboard event listeners\n if (typeof window !== \"undefined\" && this.handleKeyDown) {\n window.removeEventListener(\"keydown\", this.handleKeyDown);\n }\n }\n\n private handleKeyDown(event: KeyboardEvent) {\n // On web, we can simulate volume key detection using specific keys\n // This is a fallback since web doesn't have direct access to volume keys\n let keyType: \"up\" | \"down\" | null = null;\n\n if (event.code === \"ArrowUp\" && event.altKey) {\n keyType = \"up\";\n } else if (event.code === \"ArrowDown\" && event.altKey) {\n keyType = \"down\";\n }\n\n if (keyType) {\n event.preventDefault();\n this.emit(\"onVolumeButtonPressed\", { key: keyType });\n }\n }\n}\n\nexport default registerWebModule(\n ReactNativeKookitModule,\n \"ReactNativeKookitModule\"\n);\n"]}
@@ -0,0 +1,4 @@
1
+ import * as React from 'react';
2
+ import { ReactNativeKookitViewProps } from './ReactNativeKookit.types';
3
+ export default function ReactNativeKookitView(props: ReactNativeKookitViewProps): React.JSX.Element;
4
+ //# sourceMappingURL=ReactNativeKookitView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeKookitView.d.ts","sourceRoot":"","sources":["../src/ReactNativeKookitView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AAKvE,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,KAAK,EAAE,0BAA0B,qBAE9E"}
@@ -0,0 +1,7 @@
1
+ import { requireNativeView } from 'expo';
2
+ import * as React from 'react';
3
+ const NativeView = requireNativeView('ReactNativeKookit');
4
+ export default function ReactNativeKookitView(props) {
5
+ return <NativeView {...props}/>;
6
+ }
7
+ //# sourceMappingURL=ReactNativeKookitView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeKookitView.js","sourceRoot":"","sources":["../src/ReactNativeKookitView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,MAAM,UAAU,GACd,iBAAiB,CAAC,mBAAmB,CAAC,CAAC;AAEzC,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,KAAiC;IAC7E,OAAO,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AACnC,CAAC","sourcesContent":["import { requireNativeView } from 'expo';\nimport * as React from 'react';\n\nimport { ReactNativeKookitViewProps } from './ReactNativeKookit.types';\n\nconst NativeView: React.ComponentType<ReactNativeKookitViewProps> =\n requireNativeView('ReactNativeKookit');\n\nexport default function ReactNativeKookitView(props: ReactNativeKookitViewProps) {\n return <NativeView {...props} />;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import * as React from 'react';
2
+ import { ReactNativeKookitViewProps } from './ReactNativeKookit.types';
3
+ export default function ReactNativeKookitView(props: ReactNativeKookitViewProps): React.JSX.Element;
4
+ //# sourceMappingURL=ReactNativeKookitView.web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeKookitView.web.d.ts","sourceRoot":"","sources":["../src/ReactNativeKookitView.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AAEvE,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,KAAK,EAAE,0BAA0B,qBAU9E"}
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ export default function ReactNativeKookitView(props) {
3
+ return (<div>
4
+ <iframe style={{ flex: 1 }} src={props.url} onLoad={() => props.onLoad({ nativeEvent: { url: props.url } })}/>
5
+ </div>);
6
+ }
7
+ //# sourceMappingURL=ReactNativeKookitView.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeKookitView.web.js","sourceRoot":"","sources":["../src/ReactNativeKookitView.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,KAAiC;IAC7E,OAAO,CACL,CAAC,GAAG,CACF;MAAA,CAAC,MAAM,CACL,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CACnB,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CACf,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAEpE;IAAA,EAAE,GAAG,CAAC,CACP,CAAC;AACJ,CAAC","sourcesContent":["import * as React from 'react';\n\nimport { ReactNativeKookitViewProps } from './ReactNativeKookit.types';\n\nexport default function ReactNativeKookitView(props: ReactNativeKookitViewProps) {\n return (\n <div>\n <iframe\n style={{ flex: 1 }}\n src={props.url}\n onLoad={() => props.onLoad({ nativeEvent: { url: props.url } })}\n />\n </div>\n );\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export { default } from './ReactNativeKookitModule';
2
+ export { default as ReactNativeKookitView } from './ReactNativeKookitView';
3
+ export * from './ReactNativeKookit.types';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,cAAe,2BAA2B,CAAC"}
package/build/index.js ADDED
@@ -0,0 +1,6 @@
1
+ // Reexport the native module. On web, it will be resolved to ReactNativeKookitModule.web.ts
2
+ // and on native platforms to ReactNativeKookitModule.ts
3
+ export { default } from './ReactNativeKookitModule';
4
+ export { default as ReactNativeKookitView } from './ReactNativeKookitView';
5
+ export * from './ReactNativeKookit.types';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,wDAAwD;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,cAAe,2BAA2B,CAAC","sourcesContent":["// Reexport the native module. On web, it will be resolved to ReactNativeKookitModule.web.ts\n// and on native platforms to ReactNativeKookitModule.ts\nexport { default } from './ReactNativeKookitModule';\nexport { default as ReactNativeKookitView } from './ReactNativeKookitView';\nexport * from './ReactNativeKookit.types';\n"]}
@@ -0,0 +1,9 @@
1
+ {
2
+ "platforms": ["apple", "android", "web"],
3
+ "apple": {
4
+ "modules": ["ReactNativeKookitModule"]
5
+ },
6
+ "android": {
7
+ "modules": ["expo.modules.kookit.ReactNativeKookitModule"]
8
+ }
9
+ }
@@ -0,0 +1,29 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'ReactNativeKookit'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.description = package['description']
10
+ s.license = package['license']
11
+ s.author = package['author']
12
+ s.homepage = package['homepage']
13
+ s.platforms = {
14
+ :ios => '15.1',
15
+ :tvos => '15.1'
16
+ }
17
+ s.swift_version = '5.4'
18
+ s.source = { git: 'https://github.com/troyeguo/react-native-kookit' }
19
+ s.static_framework = true
20
+
21
+ s.dependency 'ExpoModulesCore'
22
+
23
+ # Swift/Objective-C compatibility
24
+ s.pod_target_xcconfig = {
25
+ 'DEFINES_MODULE' => 'YES',
26
+ }
27
+
28
+ s.source_files = "**/*.{h,m,mm,swift,hpp,cpp}"
29
+ end
@@ -0,0 +1,156 @@
1
+ import ExpoModulesCore
2
+ import MediaPlayer
3
+ import AVFoundation
4
+
5
+ public class ReactNativeKookitModule: Module {
6
+ private var volumeView: MPVolumeView?
7
+ private var isVolumeListenerEnabled = false
8
+ private var initialVolume: Float = 0.5
9
+
10
+ public func definition() -> ModuleDefinition {
11
+ // Sets the name of the module that JavaScript code will use to refer to the module. Takes a string as an argument.
12
+ // Can be inferred from module's class name, but it's recommended to set it explicitly for clarity.
13
+ // The module will be accessible from `requireNativeModule('ReactNativeKookit')` in JavaScript.
14
+ Name("ReactNativeKookit")
15
+
16
+ // Sets constant properties on the module. Can take a dictionary or a closure that returns a dictionary.
17
+ Constants([
18
+ "PI": Double.pi
19
+ ])
20
+
21
+ // Defines event names that the module can send to JavaScript.
22
+ Events("onChange", "onVolumeButtonPressed")
23
+
24
+ // Function to enable volume key interception
25
+ Function("enableVolumeKeyInterception") {
26
+ self.enableVolumeKeyInterception()
27
+ }
28
+
29
+ // Function to disable volume key interception
30
+ Function("disableVolumeKeyInterception") {
31
+ self.disableVolumeKeyInterception()
32
+ }
33
+
34
+ // Defines a JavaScript synchronous function that runs the native code on the JavaScript thread.
35
+ Function("hello") {
36
+ return "Hello world! 👋"
37
+ }
38
+
39
+ // Defines a JavaScript function that always returns a Promise and whose native code
40
+ // is by default dispatched on the different thread than the JavaScript runtime runs on.
41
+ AsyncFunction("setValueAsync") { (value: String) in
42
+ // Send an event to JavaScript.
43
+ self.sendEvent("onChange", [
44
+ "value": value
45
+ ])
46
+ }
47
+
48
+ // Enables the module to be used as a native view. Definition components that are accepted as part of the
49
+ // view definition: Prop, Events.
50
+ View(ReactNativeKookitView.self) {
51
+ // Defines a setter for the `url` prop.
52
+ Prop("url") { (view: ReactNativeKookitView, url: URL) in
53
+ if view.webView.url != url {
54
+ view.webView.load(URLRequest(url: url))
55
+ }
56
+ }
57
+
58
+ Events("onLoad")
59
+ }
60
+ }
61
+
62
+ private func enableVolumeKeyInterception() {
63
+ guard !isVolumeListenerEnabled else { return }
64
+
65
+ isVolumeListenerEnabled = true
66
+
67
+ // Store initial volume to restore it later
68
+ initialVolume = AVAudioSession.sharedInstance().outputVolume
69
+
70
+ // Create a hidden MPVolumeView to intercept volume button presses
71
+ volumeView = MPVolumeView(frame: CGRect(x: -2000, y: -2000, width: 1, height: 1))
72
+ volumeView?.showsVolumeSlider = true // Need to show slider to intercept
73
+ volumeView?.showsRouteButton = false
74
+ volumeView?.isUserInteractionEnabled = false
75
+ volumeView?.alpha = 0.01 // Make it almost invisible
76
+ volumeView?.clipsToBounds = true
77
+
78
+ // Add to main window and make sure it's hidden
79
+ if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
80
+ let window = windowScene.windows.first {
81
+ window.addSubview(volumeView!)
82
+ volumeView?.isHidden = false
83
+ }
84
+
85
+ // Listen for volume changes using KVO
86
+ AVAudioSession.sharedInstance().addObserver(
87
+ self,
88
+ forKeyPath: "outputVolume",
89
+ options: [.new, .old],
90
+ context: nil
91
+ )
92
+
93
+ // Also use notification as backup
94
+ NotificationCenter.default.addObserver(
95
+ self,
96
+ selector: #selector(systemVolumeChanged),
97
+ name: NSNotification.Name(rawValue: "AVSystemController_SystemVolumeDidChangeNotification"),
98
+ object: nil
99
+ )
100
+ }
101
+
102
+ private func disableVolumeKeyInterception() {
103
+ guard isVolumeListenerEnabled else { return }
104
+
105
+ isVolumeListenerEnabled = false
106
+
107
+ // Remove KVO observer
108
+ AVAudioSession.sharedInstance().removeObserver(self, forKeyPath: "outputVolume")
109
+
110
+ // Remove volume view
111
+ volumeView?.removeFromSuperview()
112
+ volumeView = nil
113
+
114
+ // Remove notification observers
115
+ NotificationCenter.default.removeObserver(self)
116
+ }
117
+
118
+ override public func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
119
+ guard isVolumeListenerEnabled,
120
+ keyPath == "outputVolume",
121
+ let change = change else { return }
122
+
123
+ let newVolume = change[.newKey] as? Float ?? initialVolume
124
+ let oldVolume = change[.oldKey] as? Float ?? initialVolume
125
+
126
+ // Determine direction
127
+ let keyType: String
128
+ if newVolume > oldVolume {
129
+ keyType = "up"
130
+ } else if newVolume < oldVolume {
131
+ keyType = "down"
132
+ } else {
133
+ return // No change
134
+ }
135
+
136
+ // Reset volume to initial value to prevent actual volume change
137
+ DispatchQueue.main.async {
138
+ // Find the volume slider and set it back
139
+ if let volumeSlider = self.volumeView?.subviews.compactMap({ $0 as? UISlider }).first {
140
+ volumeSlider.setValue(self.initialVolume, animated: false)
141
+ }
142
+ }
143
+
144
+ // Send event to JavaScript
145
+ sendEvent("onVolumeButtonPressed", [
146
+ "key": keyType
147
+ ])
148
+ }
149
+
150
+ @objc private func systemVolumeChanged(_ notification: Notification) {
151
+ // This is a backup method in case KVO doesn't work
152
+ guard isVolumeListenerEnabled else { return }
153
+
154
+ // The main logic is handled in observeValue
155
+ }
156
+ }
@@ -0,0 +1,38 @@
1
+ import ExpoModulesCore
2
+ import WebKit
3
+
4
+ // This view will be used as a native component. Make sure to inherit from `ExpoView`
5
+ // to apply the proper styling (e.g. border radius and shadows).
6
+ class ReactNativeKookitView: ExpoView {
7
+ let webView = WKWebView()
8
+ let onLoad = EventDispatcher()
9
+ var delegate: WebViewDelegate?
10
+
11
+ required init(appContext: AppContext? = nil) {
12
+ super.init(appContext: appContext)
13
+ clipsToBounds = true
14
+ delegate = WebViewDelegate { url in
15
+ self.onLoad(["url": url])
16
+ }
17
+ webView.navigationDelegate = delegate
18
+ addSubview(webView)
19
+ }
20
+
21
+ override func layoutSubviews() {
22
+ webView.frame = bounds
23
+ }
24
+ }
25
+
26
+ class WebViewDelegate: NSObject, WKNavigationDelegate {
27
+ let onUrlChange: (String) -> Void
28
+
29
+ init(onUrlChange: @escaping (String) -> Void) {
30
+ self.onUrlChange = onUrlChange
31
+ }
32
+
33
+ func webView(_ webView: WKWebView, didFinish navigation: WKNavigation) {
34
+ if let url = webView.url {
35
+ onUrlChange(url.absoluteString)
36
+ }
37
+ }
38
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "react-native-kookit",
3
+ "version": "0.1.0",
4
+ "description": "My new module",
5
+ "main": "build/index.js",
6
+ "types": "build/index.d.ts",
7
+ "scripts": {
8
+ "build": "expo-module build",
9
+ "clean": "expo-module clean",
10
+ "lint": "expo-module lint",
11
+ "test": "expo-module test",
12
+ "prepare": "expo-module prepare",
13
+ "prepublishOnly": "expo-module prepublishOnly",
14
+ "expo-module": "expo-module",
15
+ "open:ios": "xed example/ios",
16
+ "open:android": "open -a \"Android Studio\" example/android"
17
+ },
18
+ "keywords": [
19
+ "react-native",
20
+ "expo",
21
+ "react-native-kookit",
22
+ "ReactNativeKookit"
23
+ ],
24
+ "repository": "https://github.com/troyeguo/react-native-kookit",
25
+ "bugs": {
26
+ "url": "https://github.com/troyeguo/react-native-kookit/issues"
27
+ },
28
+ "author": "troyeguo <13820674+troyeguo@users.noreply.github.com> (https://github.com/troyeguo)",
29
+ "license": "MIT",
30
+ "homepage": "https://github.com/troyeguo/react-native-kookit#readme",
31
+ "dependencies": {},
32
+ "devDependencies": {
33
+ "@types/react": "~19.0.0",
34
+ "expo-module-scripts": "^4.1.10",
35
+ "expo": "~53.0.0",
36
+ "react-native": "0.79.1"
37
+ },
38
+ "peerDependencies": {
39
+ "expo": "*",
40
+ "react": "*",
41
+ "react-native": "*"
42
+ }
43
+ }
@@ -0,0 +1,24 @@
1
+ import type { StyleProp, ViewStyle } from "react-native";
2
+
3
+ export type OnLoadEventPayload = {
4
+ url: string;
5
+ };
6
+
7
+ export type VolumeKeyEventPayload = {
8
+ key: "up" | "down";
9
+ };
10
+
11
+ export type ReactNativeKookitModuleEvents = {
12
+ onChange: (params: ChangeEventPayload) => void;
13
+ onVolumeButtonPressed: (params: VolumeKeyEventPayload) => void;
14
+ };
15
+
16
+ export type ChangeEventPayload = {
17
+ value: string;
18
+ };
19
+
20
+ export type ReactNativeKookitViewProps = {
21
+ url: string;
22
+ onLoad: (event: { nativeEvent: OnLoadEventPayload }) => void;
23
+ style?: StyleProp<ViewStyle>;
24
+ };
@@ -0,0 +1,16 @@
1
+ import { NativeModule, requireNativeModule } from "expo";
2
+
3
+ import { ReactNativeKookitModuleEvents } from "./ReactNativeKookit.types";
4
+
5
+ declare class ReactNativeKookitModule extends NativeModule<ReactNativeKookitModuleEvents> {
6
+ PI: number;
7
+ hello(): string;
8
+ setValueAsync(value: string): Promise<void>;
9
+ enableVolumeKeyInterception(): void;
10
+ disableVolumeKeyInterception(): void;
11
+ }
12
+
13
+ // This call loads the native module object from the JSI.
14
+ export default requireNativeModule<ReactNativeKookitModule>(
15
+ "ReactNativeKookit"
16
+ );
@@ -0,0 +1,48 @@
1
+ import { registerWebModule, NativeModule } from "expo";
2
+
3
+ import { ReactNativeKookitModuleEvents } from "./ReactNativeKookit.types";
4
+
5
+ class ReactNativeKookitModule extends NativeModule<ReactNativeKookitModuleEvents> {
6
+ PI = Math.PI;
7
+ async setValueAsync(value: string): Promise<void> {
8
+ this.emit("onChange", { value });
9
+ }
10
+ hello() {
11
+ return "Hello world! 👋";
12
+ }
13
+ enableVolumeKeyInterception() {
14
+ // Web implementation - listen for keyboard events
15
+ if (typeof window !== "undefined") {
16
+ this.handleKeyDown = this.handleKeyDown.bind(this);
17
+ window.addEventListener("keydown", this.handleKeyDown);
18
+ }
19
+ }
20
+ disableVolumeKeyInterception() {
21
+ // Web implementation - remove keyboard event listeners
22
+ if (typeof window !== "undefined" && this.handleKeyDown) {
23
+ window.removeEventListener("keydown", this.handleKeyDown);
24
+ }
25
+ }
26
+
27
+ private handleKeyDown(event: KeyboardEvent) {
28
+ // On web, we can simulate volume key detection using specific keys
29
+ // This is a fallback since web doesn't have direct access to volume keys
30
+ let keyType: "up" | "down" | null = null;
31
+
32
+ if (event.code === "ArrowUp" && event.altKey) {
33
+ keyType = "up";
34
+ } else if (event.code === "ArrowDown" && event.altKey) {
35
+ keyType = "down";
36
+ }
37
+
38
+ if (keyType) {
39
+ event.preventDefault();
40
+ this.emit("onVolumeButtonPressed", { key: keyType });
41
+ }
42
+ }
43
+ }
44
+
45
+ export default registerWebModule(
46
+ ReactNativeKookitModule,
47
+ "ReactNativeKookitModule"
48
+ );
@@ -0,0 +1,11 @@
1
+ import { requireNativeView } from 'expo';
2
+ import * as React from 'react';
3
+
4
+ import { ReactNativeKookitViewProps } from './ReactNativeKookit.types';
5
+
6
+ const NativeView: React.ComponentType<ReactNativeKookitViewProps> =
7
+ requireNativeView('ReactNativeKookit');
8
+
9
+ export default function ReactNativeKookitView(props: ReactNativeKookitViewProps) {
10
+ return <NativeView {...props} />;
11
+ }
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+
3
+ import { ReactNativeKookitViewProps } from './ReactNativeKookit.types';
4
+
5
+ export default function ReactNativeKookitView(props: ReactNativeKookitViewProps) {
6
+ return (
7
+ <div>
8
+ <iframe
9
+ style={{ flex: 1 }}
10
+ src={props.url}
11
+ onLoad={() => props.onLoad({ nativeEvent: { url: props.url } })}
12
+ />
13
+ </div>
14
+ );
15
+ }
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ // Reexport the native module. On web, it will be resolved to ReactNativeKookitModule.web.ts
2
+ // and on native platforms to ReactNativeKookitModule.ts
3
+ export { default } from './ReactNativeKookitModule';
4
+ export { default as ReactNativeKookitView } from './ReactNativeKookitView';
5
+ export * from './ReactNativeKookit.types';
@@ -0,0 +1,25 @@
1
+ #!/bin/bash
2
+
3
+ echo "🔧 Building React Native Kookit Module..."
4
+
5
+ # Build the module
6
+ npm run build
7
+
8
+ if [ $? -eq 0 ]; then
9
+ echo "✅ Module built successfully!"
10
+ echo ""
11
+ echo "📱 To test volume key interception:"
12
+ echo "1. Make sure your MainActivity implements VolumeKeyInterceptActivity (see VOLUME_KEYS.md)"
13
+ echo "2. Run the example app: cd example && npm run android"
14
+ echo "3. Enable volume interception in the app"
15
+ echo "4. Press physical volume keys to test"
16
+ echo ""
17
+ echo "📋 Expected behavior:"
18
+ echo "- Volume HUD should NOT appear"
19
+ echo "- System volume should NOT change"
20
+ echo "- App should show alert with 'up' or 'down' key events"
21
+ echo ""
22
+ echo "📖 See VOLUME_KEYS.md for detailed implementation guide"
23
+ else
24
+ echo "❌ Build failed. Please check errors above."
25
+ fi
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ // @generated by expo-module-scripts
2
+ {
3
+ "extends": "expo-module-scripts/tsconfig.base",
4
+ "compilerOptions": {
5
+ "outDir": "./build"
6
+ },
7
+ "include": ["./src"],
8
+ "exclude": ["**/__mocks__/*", "**/__tests__/*", "**/__rsc_tests__/*"]
9
+ }