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

Initial commit

parent 9868cd0f
/** import React, {useState, useEffect} from 'react';
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*/
import React from 'react';
import type {PropsWithChildren} from 'react';
import { import {
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
Text,
useColorScheme,
View, View,
Button,
Text,
NativeModules,
Platform,
NativeEventEmitter,
} from 'react-native'; } from 'react-native';
import { const MyModuleMdd = NativeModules.MyModuleMdd;
Colors, const MyCustomEventEmitter = new NativeEventEmitter(MyModuleMdd);
DebugInstructions,
Header, const App = () => {
LearnMoreLinks, const [balance, setBalance] = useState(0);
ReloadInstructions, const [nfcInitialized] = useState(false);
} from 'react-native/Libraries/NewAppScreen';
useEffect(() => {
type SectionProps = PropsWithChildren<{ if (Platform.OS === 'android') {
title: string; // Check if MyNFCModuleMdd is available
}>; if (MyModuleMdd) {
// Initialize MyNFCModuleMdd
function Section({children, title}: SectionProps): React.JSX.Element { MyModuleMdd.initNfc();
const isDarkMode = useColorScheme() === 'dark'; } else {
return ( console.error('MyNFCModuleMdd is not available.');
<View style={styles.sectionContainer}> }
<Text }
style={[ }, []);
styles.sectionTitle,
{ MyCustomEventEmitter.addListener('MyEvent', event => {
color: isDarkMode ? Colors.white : Colors.black, console.log(event.message);
}, });
]}>
{title} const handleUpdateBalance = () => {
</Text> const newBalance = 100; // Example new balance
<Text console.warn(nfcInitialized);
style={[ MyModuleMdd.initNfc();
styles.sectionDescription,
{ MyModuleMdd.updateBalance(newBalance);
color: isDarkMode ? Colors.light : Colors.dark, // You can also call a method to retrieve the updated balance here if needed
}, };
]}>
{children}
</Text>
</View>
);
}
function App(): React.JSX.Element { const handleGetBalance = () => {
const isDarkMode = useColorScheme() === 'dark'; MyModuleMdd.initNfc();
const backgroundStyle = { MyModuleMdd.getBalance();
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
}; };
return ( return (
<SafeAreaView style={backgroundStyle}> <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<StatusBar <Text>Current Balance: {balance}</Text>
barStyle={isDarkMode ? 'light-content' : 'dark-content'} {Platform.OS === 'android' && (
backgroundColor={backgroundStyle.backgroundColor} <Button title="Update Balance" onPress={handleUpdateBalance} />
/> )}
<ScrollView <Button title="Get Balance" onPress={handleGetBalance} />
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> </View>
</ScrollView>
</SafeAreaView>
); );
} };
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; export default App;
...@@ -72,7 +72,7 @@ def jscFlavor = 'org.webkit:android-jsc:+' ...@@ -72,7 +72,7 @@ def jscFlavor = 'org.webkit:android-jsc:+'
android { android {
ndkVersion rootProject.ext.ndkVersion ndkVersion rootProject.ext.ndkVersion
buildToolsVersion rootProject.ext.buildToolsVersion buildToolsVersion rootProject.ext.buildToolsVersion
compileSdk rootProject.ext.compileSdkVersion compileSdkVersion rootProject.ext.compileSdkVersion
namespace "com.rn_mdd_simulator" namespace "com.rn_mdd_simulator"
defaultConfig { defaultConfig {
...@@ -104,8 +104,29 @@ android { ...@@ -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 { dependencies {
// The version of react-native is set by the React Native Gradle Plugin // 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:react-android")
implementation("com.facebook.react:flipper-integration") implementation("com.facebook.react:flipper-integration")
......
package com.rn_mdd_simulator package com.rn_mdd_simulator
import android.app.Application import android.app.Application
import android.os.StrictMode
import com.facebook.react.PackageList import com.facebook.react.PackageList
import com.facebook.react.ReactApplication import com.facebook.react.ReactApplication
import com.facebook.react.ReactHost import com.facebook.react.ReactHost
...@@ -10,6 +11,7 @@ import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load ...@@ -10,6 +11,7 @@ import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.facebook.react.defaults.DefaultReactNativeHost import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.react.flipper.ReactNativeFlipper import com.facebook.react.flipper.ReactNativeFlipper
import com.facebook.react.shell.MainReactPackage
import com.facebook.soloader.SoLoader import com.facebook.soloader.SoLoader
class MainApplication : Application(), ReactApplication { class MainApplication : Application(), ReactApplication {
...@@ -19,7 +21,7 @@ class MainApplication : Application(), ReactApplication { ...@@ -19,7 +21,7 @@ class MainApplication : Application(), ReactApplication {
override fun getPackages(): List<ReactPackage> = override fun getPackages(): List<ReactPackage> =
PackageList(this).packages.apply { PackageList(this).packages.apply {
// Packages that cannot be autolinked yet can be added manually here, for example: // Packages that cannot be autolinked yet can be added manually here, for example:
// add(MyReactNativePackage()) add(MyModuleMddPackage())
} }
override fun getJSMainModuleName(): String = "index" override fun getJSMainModuleName(): String = "index"
......
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 { buildscript {
ext { ext {
buildToolsVersion = "34.0.0" buildToolsVersion = "34.0.0"
minSdkVersion = 21 minSdkVersion = 24
compileSdkVersion = 34 compileSdkVersion = 34
targetSdkVersion = 34 targetSdkVersion = 34
ndkVersion = "25.1.8937393" ndkVersion = "25.1.8937393"
kotlinVersion = "1.8.0" kotlinVersion = "1.8.0"
} }
repositories { repositories {
google() maven {
url = "https://mobile-repo.mdd.co.id:8081/artifactory/android-library"
credentials {
username = "admin"
password = "Mddcoid*123#"
}
}
mavenCentral() mavenCentral()
google()
} }
dependencies { dependencies {
classpath("com.android.tools.build:gradle") classpath("com.android.tools.build:gradle")
classpath("com.facebook.react:react-native-gradle-plugin") classpath("com.facebook.react:react-native-gradle-plugin")
classpath("org.jetbrains.kotlin:kotlin-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 ...@@ -39,3 +39,4 @@ newArchEnabled=false
# Use this property to enable or disable the Hermes JS engine. # Use this property to enable or disable the Hermes JS engine.
# If set to false, you will be using JSC instead. # If set to false, you will be using JSC instead.
hermesEnabled=true hermesEnabled=true
org.gradle.offline=false
\ No newline at end of file
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists 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 networkTimeout=10000
validateDistributionUrl=true validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
......
This diff is collapsed.
...@@ -544,7 +544,7 @@ ...@@ -544,7 +544,7 @@
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES; ENABLE_TESTABILITY = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = ""; "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO; GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES; GCC_NO_COMMON_BLOCKS = YES;
...@@ -572,6 +572,7 @@ ...@@ -572,6 +572,7 @@
); );
MTL_ENABLE_DEBUG_INFO = YES; MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "$(inherited)";
OTHER_CPLUSPLUSFLAGS = ( OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)", "$(OTHER_CFLAGS)",
"-DFOLLY_NO_CONFIG", "-DFOLLY_NO_CONFIG",
...@@ -579,7 +580,13 @@ ...@@ -579,7 +580,13 @@
"-DFOLLY_USE_LIBCPP=1", "-DFOLLY_USE_LIBCPP=1",
"-DFOLLY_CFG_NO_COROUTINES=1", "-DFOLLY_CFG_NO_COROUTINES=1",
); );
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos; SDKROOT = iphoneos;
USE_HERMES = true;
}; };
name = Debug; name = Debug;
}; };
...@@ -616,7 +623,7 @@ ...@@ -616,7 +623,7 @@
COPY_PHASE_STRIP = YES; COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO; ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_STRICT_OBJC_MSGSEND = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = ""; "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES; GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
...@@ -636,6 +643,7 @@ ...@@ -636,6 +643,7 @@
"\"$(inherited)\"", "\"$(inherited)\"",
); );
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
OTHER_CFLAGS = "$(inherited)";
OTHER_CPLUSPLUSFLAGS = ( OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)", "$(OTHER_CFLAGS)",
"-DFOLLY_NO_CONFIG", "-DFOLLY_NO_CONFIG",
...@@ -643,7 +651,13 @@ ...@@ -643,7 +651,13 @@
"-DFOLLY_USE_LIBCPP=1", "-DFOLLY_USE_LIBCPP=1",
"-DFOLLY_CFG_NO_COROUTINES=1", "-DFOLLY_CFG_NO_COROUTINES=1",
); );
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos; SDKROOT = iphoneos;
USE_HERMES = true;
VALIDATE_PRODUCT = YES; VALIDATE_PRODUCT = YES;
}; };
name = Release; 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