Commit 300f89fc authored by Gandha Ryanto's avatar Gandha Ryanto

Initial commit

parent 9868cd0f
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*/
import React from 'react';
import type {PropsWithChildren} from 'react';
import React, {useState, useEffect} from 'react';
import {
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
Text,
useColorScheme,
View,
Button,
Text,
NativeModules,
Platform,
NativeEventEmitter,
} from 'react-native';
import {
Colors,
DebugInstructions,
Header,
LearnMoreLinks,
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
type SectionProps = PropsWithChildren<{
title: string;
}>;
function Section({children, title}: SectionProps): React.JSX.Element {
const isDarkMode = useColorScheme() === 'dark';
return (
<View style={styles.sectionContainer}>
<Text
style={[
styles.sectionTitle,
{
color: isDarkMode ? Colors.white : Colors.black,
},
]}>
{title}
</Text>
<Text
style={[
styles.sectionDescription,
{
color: isDarkMode ? Colors.light : Colors.dark,
},
]}>
{children}
</Text>
</View>
);
}
const MyModuleMdd = NativeModules.MyModuleMdd;
const MyCustomEventEmitter = new NativeEventEmitter(MyModuleMdd);
const App = () => {
const [balance, setBalance] = useState(0);
const [nfcInitialized] = useState(false);
useEffect(() => {
if (Platform.OS === 'android') {
// Check if MyNFCModuleMdd is available
if (MyModuleMdd) {
// Initialize MyNFCModuleMdd
MyModuleMdd.initNfc();
} else {
console.error('MyNFCModuleMdd is not available.');
}
}
}, []);
MyCustomEventEmitter.addListener('MyEvent', event => {
console.log(event.message);
});
const handleUpdateBalance = () => {
const newBalance = 100; // Example new balance
console.warn(nfcInitialized);
MyModuleMdd.initNfc();
MyModuleMdd.updateBalance(newBalance);
// You can also call a method to retrieve the updated balance here if needed
};
function App(): React.JSX.Element {
const isDarkMode = useColorScheme() === 'dark';
const handleGetBalance = () => {
MyModuleMdd.initNfc();
const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
MyModuleMdd.getBalance();
};
return (
<SafeAreaView style={backgroundStyle}>
<StatusBar
barStyle={isDarkMode ? 'light-content' : 'dark-content'}
backgroundColor={backgroundStyle.backgroundColor}
/>
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={backgroundStyle}>
<Header />
<View
style={{
backgroundColor: isDarkMode ? Colors.black : Colors.white,
}}>
<Section title="Step One">
Edit <Text style={styles.highlight}>App.tsx</Text> to change this
screen and then come back to see your edits.
</Section>
<Section title="See Your Changes">
<ReloadInstructions />
</Section>
<Section title="Debug">
<DebugInstructions />
</Section>
<Section title="Learn More">
Read the docs to discover what to do next:
</Section>
<LearnMoreLinks />
</View>
</ScrollView>
</SafeAreaView>
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<Text>Current Balance: {balance}</Text>
{Platform.OS === 'android' && (
<Button title="Update Balance" onPress={handleUpdateBalance} />
)}
<Button title="Get Balance" onPress={handleGetBalance} />
</View>
);
}
const styles = StyleSheet.create({
sectionContainer: {
marginTop: 32,
paddingHorizontal: 24,
},
sectionTitle: {
fontSize: 24,
fontWeight: '600',
},
sectionDescription: {
marginTop: 8,
fontSize: 18,
fontWeight: '400',
},
highlight: {
fontWeight: '700',
},
});
};
export default App;
......@@ -72,7 +72,7 @@ def jscFlavor = 'org.webkit:android-jsc:+'
android {
ndkVersion rootProject.ext.ndkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileSdk rootProject.ext.compileSdkVersion
compileSdkVersion rootProject.ext.compileSdkVersion
namespace "com.rn_mdd_simulator"
defaultConfig {
......@@ -104,8 +104,29 @@ android {
}
}
repositories {
maven {
url = "https://mobile-repo.mdd.co.id:8081/artifactory/android-library"
credentials {
username = "admin"
password = "Mddcoid*123#"
}
}
}
dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation(group: 'com.mdd.topup', name: 'mdd_nfc_manager_android-release', version: '1.0.1', ext: 'aar')
//retrofit
implementation("io.reactivex.rxjava2:rxjava:2.2.19")
implementation("io.reactivex.rxjava2:rxandroid:2.1.1")
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:adapter-rxjava:2.9.0")
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.11.0")
implementation("com.squareup.retrofit2:converter-scalars:2.9.0")
implementation("com.facebook.react:react-android")
implementation("com.facebook.react:flipper-integration")
......
package com.rn_mdd_simulator
import android.app.Application
import android.os.StrictMode
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactHost
......@@ -10,36 +11,37 @@ import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.react.flipper.ReactNativeFlipper
import com.facebook.react.shell.MainReactPackage
import com.facebook.soloader.SoLoader
class MainApplication : Application(), ReactApplication {
override val reactNativeHost: ReactNativeHost =
object : DefaultReactNativeHost(this) {
override fun getPackages(): List<ReactPackage> =
PackageList(this).packages.apply {
// Packages that cannot be autolinked yet can be added manually here, for example:
// add(MyReactNativePackage())
}
override fun getJSMainModuleName(): String = "index"
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
}
override val reactHost: ReactHost
get() = getDefaultReactHost(this.applicationContext, reactNativeHost)
override fun onCreate() {
super.onCreate()
SoLoader.init(this, false)
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
load()
override val reactNativeHost: ReactNativeHost =
object : DefaultReactNativeHost(this) {
override fun getPackages(): List<ReactPackage> =
PackageList(this).packages.apply {
// Packages that cannot be autolinked yet can be added manually here, for example:
add(MyModuleMddPackage())
}
override fun getJSMainModuleName(): String = "index"
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
}
override val reactHost: ReactHost
get() = getDefaultReactHost(this.applicationContext, reactNativeHost)
override fun onCreate() {
super.onCreate()
SoLoader.init(this, false)
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
load()
}
ReactNativeFlipper.initializeFlipper(this, reactNativeHost.reactInstanceManager)
}
ReactNativeFlipper.initializeFlipper(this, reactNativeHost.reactInstanceManager)
}
}
package com.rn_mdd_simulator
import android.app.Activity
import android.content.Intent
import android.os.StrictMode
import android.util.Log
import com.facebook.react.bridge.ActivityEventListener
import com.facebook.react.bridge.LifecycleEventListener
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.WritableNativeMap
import com.facebook.react.modules.core.DeviceEventManagerModule
import id.mdd.mdd_nfc_manager_android.MddNfcManager
class MyModuleMdd(private val reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext), ActivityEventListener, LifecycleEventListener {
private var currentState = MddNfcManager.NfcState.CARD_INFO
private val TAG: String = "MyModuleMdd"
private var nfcManager: MddNfcManager? = null
private var eventEmitter: DeviceEventManagerModule.RCTDeviceEventEmitter? = null
override fun getName(): String {
return "MyModuleMdd"
}
override fun initialize() {
super.initialize()
reactContext.addActivityEventListener(this);
reactContext.addLifecycleEventListener(this);
eventEmitter = reactApplicationContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
nfcManager = MddNfcManager(
reactApplicationContext,
currentActivity,
"1234567abc",
"165eea86947a4e9483d1902f93495fc6",
"355933093746314",
0
)
}
override fun onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy()
eventEmitter = null
}
@ReactMethod
fun initNfc() {
println("initNfc called")
nfcManager?.startNfc()
val params = WritableNativeMap()
params.putString("message", "initNfc triggered from Kotlin!")
eventEmitter?.emit("MyEvent", params)
}
@ReactMethod
fun updateBalance(newBalance: Double) {
// Update balance code
println("update balance called")
currentState = MddNfcManager.NfcState.UPDATE
val params = WritableNativeMap()
params.putString("message", "update balance triggered from Kotlin!")
eventEmitter?.emit("MyEvent", params)
}
@ReactMethod
fun getBalance() {
// Get balance code
println("get balance called")
currentState = MddNfcManager.NfcState.CARD_INFO
val params = WritableNativeMap()
params.putString("message", "get balance triggered from Kotlin!")
eventEmitter?.emit("MyEvent", params)
}
override fun onActivityResult(p0: Activity?, p1: Int, p2: Int, p3: Intent?) {
Log.d(TAG, "onActivityResult")
}
override fun onNewIntent(intent: Intent) {
Log.d(TAG, "onNewIntent")
if (currentState == MddNfcManager.NfcState.CARD_INFO) {
nfcManager?.getCardInfo(intent)
} else if (currentState == MddNfcManager.NfcState.UPDATE) {
nfcManager?.update(intent, "081514230108", "gandharyanto@gmail.com")
}
}
override fun onHostResume() {
Log.d(TAG, "onHostResume")
}
override fun onHostPause() {
Log.d(TAG, "onHostPause")
}
override fun onHostDestroy() {
Log.d(TAG, "onHostDestroy")
}
}
package com.rn_mdd_simulator
import android.view.View
import com.facebook.react.ReactPackage
import com.facebook.react.bridge.JavaScriptModule
import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.uimanager.ReactShadowNode
import com.facebook.react.uimanager.ViewManager
import java.util.Collections
class MyModuleMddPackage : ReactPackage {
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
val modules: MutableList<NativeModule> = ArrayList()
// Add MyNFCModuleMdd to the list of native modules
modules.add(MyModuleMdd(reactContext)) // Assuming MyNFCModuleMdd is the class that implements the NFC functionality
return modules
}
override fun createViewManagers(p0: ReactApplicationContext): MutableList<ViewManager<View, ReactShadowNode<*>>> {
return Collections.emptyList();
}
// Deprecated from RN 0.47
fun createJSModules(): List<Class<out JavaScriptModule?>> {
return emptyList()
}
}
\ No newline at end of file
buildscript {
ext {
buildToolsVersion = "34.0.0"
minSdkVersion = 21
minSdkVersion = 24
compileSdkVersion = 34
targetSdkVersion = 34
ndkVersion = "25.1.8937393"
kotlinVersion = "1.8.0"
}
repositories {
google()
maven {
url = "https://mobile-repo.mdd.co.id:8081/artifactory/android-library"
credentials {
username = "admin"
password = "Mddcoid*123#"
}
}
mavenCentral()
google()
}
dependencies {
classpath("com.android.tools.build:gradle")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
classpath("org.jfrog.buildinfo:build-info-extractor-gradle:4.28.1")
}
}
......
......@@ -39,3 +39,4 @@ newArchEnabled=false
# Use this property to enable or disable the Hermes JS engine.
# If set to false, you will be using JSC instead.
hermesEnabled=true
org.gradle.offline=false
\ No newline at end of file
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
......
This diff is collapsed.
......@@ -544,7 +544,7 @@
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
......@@ -572,6 +572,7 @@
);
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "$(inherited)";
OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)",
"-DFOLLY_NO_CONFIG",
......@@ -579,7 +580,13 @@
"-DFOLLY_USE_LIBCPP=1",
"-DFOLLY_CFG_NO_COROUTINES=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
};
name = Debug;
};
......@@ -616,7 +623,7 @@
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
......@@ -636,6 +643,7 @@
"\"$(inherited)\"",
);
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_CFLAGS = "$(inherited)";
OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)",
"-DFOLLY_NO_CONFIG",
......@@ -643,7 +651,13 @@
"-DFOLLY_USE_LIBCPP=1",
"-DFOLLY_CFG_NO_COROUTINES=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
VALIDATE_PRODUCT = YES;
};
name = Release;
......
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:rn_mdd_simulator.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment