Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.compile.nullAnalysis.mode": "disabled"
}
1 change: 1 addition & 0 deletions .watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.github.quarck.calnotify

import android.util.Log
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import java.util.Map;
import java.util.HashMap;

class CalendarModule constructor(context: ReactApplicationContext?) :
ReactContextBaseJavaModule(context) {
override fun getName(): String {
return "Calendar";
}

@ReactMethod
fun createCalendarEvent(name: String, location: String) {
Log.d("CalendarModule", "Create event called with name: $name and location: $location")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,56 @@
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA



// a mis mash of

// https://reactnative.dev/docs/native-modules-android?android-language=kotlin#register-the-module-android-specific
// https://reactnative.dev/docs/integration-with-android-fragment?android-language=kotlin
// https://github.com/itinance/react-native-fs/issues/1046#issue-1028007246


// because the docs are incomplete

// also learned this is really governed by
// android:name of teh application
// https://stackoverflow.com/questions/39344843/android-app-application-cannot-be-cast-to-com-facebook-react-reactapplication

package com.github.quarck.calnotify

import android.R
import android.app.Application
import android.content.Context
import com.facebook.react.BuildConfig
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.react.views.text.ReactFontManager
import com.facebook.soloader.SoLoader


// This storage is wiped every time app is restarted. Only keep variables
// that are instance-specific here
class GlobalState : android.app.Application() {
class GlobalState : Application(), ReactApplication {
var lastNotificationRePost: Long = 0
var lastTimerBroadcastReceived: Long = 0

val reactNativeHost =
object : DefaultReactNativeHost(this) {
override fun getUseDeveloperSupport() = BuildConfig.DEBUG
override fun getPackages(): List<ReactPackage>? {
val packages: MutableList<ReactPackage> = PackageList(this).packages
// Packages that cannot be autolinked yet can be added manually here, for example:
packages.add(MyAppPackage())
return packages
}
}

override fun getReactNativeHost(): ReactNativeHost = reactNativeHost


}

val Context.globalState: GlobalState?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.github.quarck.calnotify

// NOTE WARNING! TURNS OUT THIS APP DONES'T USE THIS FILE AS ITS MAIN ENTRY!!!!!!!!!!!!!!
// SEE GlobalState.kt!!!

import android.app.Application
import com.facebook.react.BuildConfig
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultReactNativeHost

// a mis mash of

// https://reactnative.dev/docs/native-modules-android?android-language=kotlin#register-the-module-android-specific
// https://reactnative.dev/docs/integration-with-android-fragment?android-language=kotlin
// https://github.com/itinance/react-native-fs/issues/1046#issue-1028007246


// because the docs are incomplete

// also learned this is really governed by
// android:name of teh application
// https://stackoverflow.com/questions/39344843/android-app-application-cannot-be-cast-to-com-facebook-react-reactapplication


//class MyReactApplication : Application(), ReactApplication {
// private val reactNativeHost =
// object : DefaultReactNativeHost(this) {
// override fun getUseDeveloperSupport() = BuildConfig.DEBUG
// override fun getPackages(): List<ReactPackage> =
// PackageList(this).packages.apply {
// // Packages that cannot be autolinked yet can be added manually here, for example:
// // packages.add(new MyReactNativePackage());
// add(MyAppPackage())
// }
// }
// override fun getReactNativeHost(): ReactNativeHost = reactNativeHost
//}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.quarck.calnotify
import android.view.View
import com.facebook.react.ReactPackage
import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.uimanager.ReactShadowNode
import com.facebook.react.uimanager.ViewManager

class MyAppPackage : ReactPackage {

override fun createViewManagers(
reactContext: ReactApplicationContext
): MutableList<ViewManager<View, ReactShadowNode<*>>> = mutableListOf()

override fun createNativeModules(
reactContext: ReactApplicationContext
): MutableList<NativeModule> = listOf(CalendarModule(reactContext)).toMutableList()
}
26 changes: 0 additions & 26 deletions index.js

This file was deleted.

44 changes: 44 additions & 0 deletions index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';
import {AppRegistry, StyleSheet, Text, View, NativeModules, Button} from 'react-native';
import CalendarModule from './src/CalendarModule';

const NewModuleButton = () => {
const onPress = () => {
console.log(NativeModules);
console.log(CalendarModule);
CalendarModule.createCalendarEvent('testName', 'testLocation');
};

return (
<Button
title="Click to invoke your native module!"
color="#841584"
onPress={onPress}
/>
);
};

const HelloWorld = () => {
return (
<View style={styles.container}>
<Text style={styles.hello}>Hello, World</Text>
<NewModuleButton />
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
hello: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
});

AppRegistry.registerComponent(
'MyReactNativeApp',
() => HelloWorld,
);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"log4js": "^6.9.1",
"react": "18.2.0",
"react-native": "^0.72.5",
"rn-game-over": "^1.1.0",
"swc-node": "^1.0.0",
"typed-emitter": "^2.1.0"
},
Expand All @@ -27,7 +28,7 @@
"@tsconfig/react-native": "^3.0.2",
"@types/jest": "^29.5.5",
"@types/node": "^20.4.5",
"@types/react": "^18.2.25",
"@types/react": "^18.2.28",
"@types/react-test-renderer": "^18.0.3",
"@typescript-eslint/eslint-plugin": "^6.6.0",
"drizzle-kit": "^0.19.13",
Expand Down
13 changes: 13 additions & 0 deletions src/CalendarModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* This exposes the native CalendarModule module as a JS module. This has a
* function 'createCalendarEvent' which takes the following parameters:
*
* 1. String name: A string representing the name of the event
* 2. String location: A string representing the location of the event
*/
import {NativeModules} from 'react-native';
const {Calendar} = NativeModules;
interface CalendarInterface {
createCalendarEvent(name: string, location: string): void;
}
export default Calendar as CalendarInterface;
8 changes: 2 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
{
"extends": ["./node_modules/gts/tsconfig-google.json", "@tsconfig/react-native/tsconfig.json"],
"compilerOptions": {
"verbatimModuleSyntax": true, // https://swc.rs/docs/migrating-from-tsc
// "verbatimModuleSyntax": true, // https://swc.rs/docs/migrating-from-tsc
"useDefineForClassFields": true,
"allowImportingTsExtensions": true,
"sourceMap": true,
"types": [
"jest"
],
},
"include": [
"src/**/*.ts",
"test/**/*.ts",
"global.d.ts"
],
"include": ["src/**/*", "test/**/*", "index.tsx" ],
"exclude": ["node_modules", "build"],
"typeRoots": ["./node_modules/@types"],
"ts-node": { // https://github.com/TypeStrong/ts-node#native-ecmascript-modules
Expand Down
Loading