expo-h3 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.
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,32 @@
1
+ # expo-h3
2
+
3
+ My new module
4
+
5
+ # API documentation
6
+
7
+ - [Documentation for the latest stable release](https://docs.expo.dev/versions/latest/sdk/h3/)
8
+ - [Documentation for the main branch](https://docs.expo.dev/versions/unversioned/sdk/h3/)
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 expo-h3
22
+ ```
23
+
24
+ ### Configure for Android
25
+
26
+
27
+
28
+
29
+
30
+ # Contributing
31
+
32
+ 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.h3'
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", 36)
27
+ defaultConfig {
28
+ minSdkVersion safeExtGet("minSdkVersion", 24)
29
+ targetSdkVersion safeExtGet("targetSdkVersion", 36)
30
+ }
31
+ }
32
+ }
33
+
34
+ android {
35
+ namespace "expo.modules.h3"
36
+ defaultConfig {
37
+ versionCode 1
38
+ versionName "0.1.0"
39
+ }
40
+ lintOptions {
41
+ abortOnError false
42
+ }
43
+ }
@@ -0,0 +1,3 @@
1
+ <manifest>
2
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
3
+ </manifest>
@@ -0,0 +1,132 @@
1
+ package expo.modules.h3
2
+
3
+ import expo.modules.kotlin.modules.Module
4
+ import expo.modules.kotlin.modules.ModuleDefinition
5
+
6
+ import android.content.Intent
7
+ import android.os.CancellationSignal
8
+ import android.os.ParcelFileDescriptor
9
+ import android.print.PageRange
10
+ import android.print.PrintAttributes
11
+ import android.print.PrintDocumentAdapter
12
+ import android.print.PrintDocumentInfo
13
+ import android.webkit.WebView
14
+ import android.webkit.WebViewClient
15
+ import android.os.Handler
16
+ import android.os.Looper
17
+ import expo.modules.kotlin.Promise
18
+ import java.io.File
19
+ import java.io.IOException
20
+
21
+ class ExpoH3Module : Module() {
22
+ override fun definition() = ModuleDefinition {
23
+ Name("ExpoH3")
24
+
25
+ // Function for printing HTML as PDF
26
+ AsyncFunction("printHtmlAsync") { html: String, promise: Promise ->
27
+ silentPrintHtml(html, promise)
28
+ }
29
+
30
+ // Function for printing plain text
31
+ AsyncFunction("printTextAsync") { text: String, promise: Promise ->
32
+ sendPrintIntent(text, "text/plain", promise)
33
+ }
34
+
35
+ // Function for sharing/printing web URL
36
+ AsyncFunction("printUrlAsync") { url: String, promise: Promise ->
37
+ sendPrintIntent(url, "text/plain", promise)
38
+ }
39
+ }
40
+
41
+ private fun silentPrintHtml(html: String, promise: Promise) {
42
+ val context = appContext.reactContext.applicationContext
43
+ val handler = Handler(Looper.getMainLooper())
44
+
45
+ handler.post {
46
+ val webView = WebView(context)
47
+ webView.webViewClient = object : WebViewClient() {
48
+ override fun onPageFinished(view: WebView?, url: String?) {
49
+ createPdfFromWebView(webView, promise)
50
+ }
51
+ }
52
+ webView.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null)
53
+ }
54
+ }
55
+
56
+ private fun createPdfFromWebView(webView: WebView, promise: Promise) {
57
+ val pdfPath = "/storage/emulated/0/temp_print.pdf"
58
+ val pdfFile = File(pdfPath)
59
+ val context = appContext.reactContext.applicationContext
60
+
61
+ try {
62
+ // Set up print attributes (A4, high res, no margins)
63
+ val attributes = PrintAttributes.Builder()
64
+ .setMediaSize(PrintAttributes.MediaSize.ISO_A4)
65
+ .setResolution(PrintAttributes.Resolution("pdf", "pdf", 600, 600))
66
+ .setMinMargins(PrintAttributes.Margins.NO_MARGINS)
67
+ .build()
68
+
69
+ val adapter = webView.createPrintDocumentAdapter("SilentPrintDoc")
70
+
71
+ // Layout the document
72
+ adapter.onLayout(null, attributes, null, object : PrintDocumentAdapter.LayoutResultCallback() {
73
+ override fun onLayoutFinished(info: PrintDocumentInfo?, changed: Boolean) {
74
+ // Write to file
75
+ val fd = ParcelFileDescriptor.open(pdfFile, ParcelFileDescriptor.MODE_READ_WRITE)
76
+ adapter.onWrite(arrayOf(PageRange.ALL_PAGES), fd, CancellationSignal(), object : PrintDocumentAdapter.WriteResultCallback() {
77
+ override fun onWriteFinished(pages: Array<out PageRange>?) {
78
+ try {
79
+ fd.close()
80
+ // Now send the print intent
81
+ val intent = Intent()
82
+ intent.action = Intent.ACTION_SEND
83
+ intent.setPackage("comb.bld.settings.print")
84
+ intent.putExtra(Intent.EXTRA_TEXT, pdfPath)
85
+ intent.type = "application/pdf"
86
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
87
+ context.startActivity(intent)
88
+
89
+ // Delete the temp file (assume print service has it now; add delay if needed for testing)
90
+ pdfFile.delete()
91
+
92
+ promise.resolve("Printed successfully")
93
+ } catch (e: Exception) {
94
+ promise.reject("PRINT_ERROR", e.message, e)
95
+ }
96
+ }
97
+
98
+ override fun onWriteFailed(error: CharSequence?) {
99
+ promise.reject("PDF_WRITE_ERROR", error.toString(), null)
100
+ }
101
+ })
102
+ }
103
+
104
+ override fun onLayoutFailed(error: CharSequence?) {
105
+ promise.reject("PDF_LAYOUT_ERROR", error.toString(), null)
106
+ }
107
+ }, null)
108
+ } catch (e: IOException) {
109
+ promise.reject("FILE_ERROR", e.message, e)
110
+ }
111
+ }
112
+
113
+ private fun sendPrintIntent(content: String, mimeType: String, promise: Promise) {
114
+ val context = appContext.reactContext.applicationContext
115
+ val handler = Handler(Looper.getMainLooper())
116
+
117
+ handler.post {
118
+ try {
119
+ val intent = Intent()
120
+ intent.action = Intent.ACTION_SEND
121
+ intent.setPackage("comb.bld.settings.print")
122
+ intent.putExtra(Intent.EXTRA_TEXT, content)
123
+ intent.type = mimeType
124
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
125
+ context.startActivity(intent)
126
+ promise.resolve("Sent successfully")
127
+ } catch (e: Exception) {
128
+ promise.reject("SEND_ERROR", e.message, e)
129
+ }
130
+ }
131
+ }
132
+ }
@@ -0,0 +1,4 @@
1
+ export type PrintHtmlAsync = (html: string) => Promise<string>;
2
+ export type PrintTextAsync = (text: string) => Promise<string>;
3
+ export type PrintUrlAsync = (url: string) => Promise<string>;
4
+ //# sourceMappingURL=ExpoH3.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoH3.types.d.ts","sourceRoot":"","sources":["../src/ExpoH3.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAC/D,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAC/D,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ExpoH3.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoH3.types.js","sourceRoot":"","sources":["../src/ExpoH3.types.ts"],"names":[],"mappings":"","sourcesContent":["export type PrintHtmlAsync = (html: string) => Promise<string>;\nexport type PrintTextAsync = (text: string) => Promise<string>;\nexport type PrintUrlAsync = (url: string) => Promise<string>;"]}
@@ -0,0 +1,10 @@
1
+ import { NativeModule } from 'expo';
2
+ import { PrintHtmlAsync, PrintTextAsync, PrintUrlAsync } from './ExpoH3.types';
3
+ declare class ExpoH3Module extends NativeModule {
4
+ printHtmlAsync: PrintHtmlAsync;
5
+ printTextAsync: PrintTextAsync;
6
+ printUrlAsync: PrintUrlAsync;
7
+ }
8
+ declare const _default: ExpoH3Module;
9
+ export default _default;
10
+ //# sourceMappingURL=ExpoH3Module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoH3Module.d.ts","sourceRoot":"","sources":["../src/ExpoH3Module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAuB,MAAM,MAAM,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/E,OAAO,OAAO,YAAa,SAAQ,YAAY;IAC7C,cAAc,EAAE,cAAc,CAAC;IAC/B,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,EAAE,aAAa,CAAC;CAC9B;;AAGD,wBAA2D"}
@@ -0,0 +1,4 @@
1
+ import { requireNativeModule } from 'expo';
2
+ // This call loads the native module object from the JSI.
3
+ export default requireNativeModule('ExpoH3');
4
+ //# sourceMappingURL=ExpoH3Module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoH3Module.js","sourceRoot":"","sources":["../src/ExpoH3Module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAUzD,yDAAyD;AACzD,eAAe,mBAAmB,CAAe,QAAQ,CAAC,CAAC","sourcesContent":["import { NativeModule, requireNativeModule } from 'expo';\n\nimport { PrintHtmlAsync, PrintTextAsync, PrintUrlAsync } from './ExpoH3.types';\n\ndeclare class ExpoH3Module extends NativeModule {\n printHtmlAsync: PrintHtmlAsync;\n printTextAsync: PrintTextAsync;\n printUrlAsync: PrintUrlAsync;\n}\n\n// This call loads the native module object from the JSI.\nexport default requireNativeModule<ExpoH3Module>('ExpoH3');"]}
@@ -0,0 +1,3 @@
1
+ export { default } from './ExpoH3Module';
2
+ export * from './ExpoH3.types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,cAAc,gBAAgB,CAAC"}
package/build/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { default } from './ExpoH3Module';
2
+ export * from './ExpoH3.types';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,cAAc,gBAAgB,CAAC","sourcesContent":["export { default } from './ExpoH3Module';\nexport * from './ExpoH3.types';"]}
@@ -0,0 +1,9 @@
1
+ {
2
+ "platforms": ["apple", "android", "web"],
3
+ "apple": {
4
+ "modules": ["ExpoH3Module"]
5
+ },
6
+ "android": {
7
+ "modules": ["expo.modules.h3.ExpoH3Module"]
8
+ }
9
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "expo-h3",
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
+ "expo-h3",
22
+ "ExpoH3"
23
+ ],
24
+ "repository": "https://github.com/Hakoblot/expo-h3",
25
+ "bugs": {
26
+ "url": "https://github.com/Hakoblot/expo-h3/issues"
27
+ },
28
+ "author": "cob-byte <jacob.barcelona@linoflaptech.com> (https://github.com/Hakoblot)",
29
+ "license": "MIT",
30
+ "homepage": "https://github.com/Hakoblot/expo-h3#readme",
31
+ "dependencies": {},
32
+ "devDependencies": {
33
+ "@types/react": "~19.1.0",
34
+ "expo-module-scripts": "^5.0.8",
35
+ "expo": "^54.0.27",
36
+ "react-native": "0.81.5"
37
+ },
38
+ "peerDependencies": {
39
+ "expo": "*",
40
+ "react": "*",
41
+ "react-native": "*"
42
+ }
43
+ }
@@ -0,0 +1,3 @@
1
+ export type PrintHtmlAsync = (html: string) => Promise<string>;
2
+ export type PrintTextAsync = (text: string) => Promise<string>;
3
+ export type PrintUrlAsync = (url: string) => Promise<string>;
@@ -0,0 +1,12 @@
1
+ import { NativeModule, requireNativeModule } from 'expo';
2
+
3
+ import { PrintHtmlAsync, PrintTextAsync, PrintUrlAsync } from './ExpoH3.types';
4
+
5
+ declare class ExpoH3Module extends NativeModule {
6
+ printHtmlAsync: PrintHtmlAsync;
7
+ printTextAsync: PrintTextAsync;
8
+ printUrlAsync: PrintUrlAsync;
9
+ }
10
+
11
+ // This call loads the native module object from the JSI.
12
+ export default requireNativeModule<ExpoH3Module>('ExpoH3');
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { default } from './ExpoH3Module';
2
+ export * from './ExpoH3.types';
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
+ }