Skip to content

Commit

Permalink
WIP Android
Browse files Browse the repository at this point in the history
  • Loading branch information
KVNLS committed Apr 2, 2024
1 parent 064327b commit 5c490c4
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,112 +8,76 @@ import android.content.res.Configuration
import android.os.Bundle
import android.view.View
import android.view.WindowManager

import expo.modules.ReactActivityDelegateWrapper
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
import com.facebook.react.defaults.DefaultReactActivityDelegate;

import com.facebook.react.defaults.DefaultReactActivityDelegate
import org.devio.rn.splashscreen.SplashScreen

import java.util.Locale

import com.facebook.react.modules.i18nmanager.I18nUtil

class MainActivity : ReactActivity() {

/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
override fun getMainComponentName(): String = "ledgerlivemobile"
override fun getMainComponentName(): String = "ledgerlivemobile"

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
setIntent(intent)
}

/**
* Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link
* DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React
* (aka React 18) with two boolean flags.
*/
override fun createReactActivityDelegate(): ReactActivityDelegate =
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)

@Override
protected void onCreate(Bundle savedInstanceState) {
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)

override fun onCreate(savedInstanceState: Bundle?) {
if (!BuildConfig.DEBUG) {
SplashScreen.show(this, true);
SplashScreen.show(this, true)
}
super.onCreate(null);
/*
* Addresses an inconvenient side-effect of using `password-visible`, that
* allowed styled texts to be pasted (receiver's address for instance) retaining
* the styles of the source text.
*/
final ClipboardManager clipboard = (ClipboardManager) this.getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard != null) {
clipboard.addPrimaryClipChangedListener(new ClipboardManager.OnPrimaryClipChangedListener() {
boolean breakLoop = false;

public void onPrimaryClipChanged() {
if (breakLoop) {
breakLoop = false;
return;
}
if (clipboard.hasPrimaryClip()) {
ClipData clipData = clipboard.getPrimaryClip();
if (clipData == null) {
// according to our logs this can happen for some users
return;
}
ClipData.Item item = clipData.getItemAt(0);
if (item == null) {
return;
}
ClipData clip = ClipData.newPlainText("overridden text",
item.coerceToText(MainActivity.this).toString());
breakLoop = true;
clipboard.setPrimaryClip(clip);
super.onCreate(null)

val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager?
clipboard?.addPrimaryClipChangedListener {
var breakLoop = false
if (clipboard.hasPrimaryClip()) {
val clipData = clipboard.primaryClip
if (clipData != null) {
val item = clipData.getItemAt(0)
if (item != null) {
val clip = ClipData.newPlainText("overridden text", item.coerceToText(this@MainActivity).toString())
breakLoop = true
clipboard.setPrimaryClip(clip)
}
}
});
}
}

I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
sharedI18nUtilInstance.allowRTL(getApplicationContext(), true);

val sharedI18nUtilInstance = I18nUtil.getInstance()
sharedI18nUtilInstance.allowRTL(applicationContext, true)
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (!hasFocus && !BuildConfig.DEBUG) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (!hasFocus && !BuildConfig.DEBUG) {
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
}


@Override
protected void onResume() {
super.onResume();

override fun onResume() {
super.onResume()
/*
* Override the detected language to english if it's a RTL language. TODO if we
* ever support a RTL language we'd have to take it into account here.
*/
Configuration config = getBaseContext().getResources().getConfiguration();
if (config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
Locale locale = new Locale("en");
Locale.setDefault(locale);
config.setLocale(locale);
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
val config = baseContext.resources.configuration
if (config.layoutDirection == View.LAYOUT_DIRECTION_RTL) {
val locale = Locale("en")
Locale.setDefault(locale)
config.setLocale(locale)
baseContext.resources.updateConfiguration(config, baseContext.resources.displayMetrics)
}
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ import com.braze.BrazeActivityLifecycleCallbackListener

class MainApplication : Application(), ReactApplication {

companion object {
const val FW_UPDATE_NOTIFICATION_PROGRESS = 1
const val FW_UPDATE_NOTIFICATION_USER = 2
}


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())
add(NativeModulesPackage());
}

override fun getJSMainModuleName(): String = "index"
Expand All @@ -38,7 +45,7 @@ class MainApplication : Application(), ReactApplication {
override fun onCreate() {
super.onCreate()
SoLoader.init(this, false)
registerActivityLifecycleCallbacks(new BrazeActivityLifecycleCallbackListener());
registerActivityLifecycleCallbacks(BrazeActivityLifecycleCallbackListener())
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
load()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.ledger.live

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 NativeModulesPackage : ReactPackage {

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

override fun createNativeModules(
reactContext: ReactApplicationContext
): MutableList<NativeModule> = listOf(
BluetoothHelperModule(reactContext),
ImagePickerModule(reactContext),
LocationHelperModule(reactContext)
).toMutableList()
}
12 changes: 7 additions & 5 deletions apps/ledger-live-mobile/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ PODS:
- lottie-ios (~> 4.4.1)
- RCT-Folly (= 2022.05.16.00)
- React-Core
- MultiplatformBleAdapter (0.1.9)
- MultiplatformBleAdapter (0.2.0)
- nanopb (2.30908.0):
- nanopb/decode (= 2.30908.0)
- nanopb/encode (= 2.30908.0)
Expand Down Expand Up @@ -1089,8 +1089,10 @@ PODS:
- React-Core
- react-native-biometrics (3.0.1):
- React-Core
- react-native-ble-plx (2.0.3):
- MultiplatformBleAdapter (= 0.1.9)
- react-native-ble-plx (3.1.2):
- glog
- MultiplatformBleAdapter (= 0.2.0)
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-config (1.5.1):
- react-native-config/App (= 1.5.1)
Expand Down Expand Up @@ -1842,7 +1844,7 @@ SPEC CHECKSUMS:
libwebp: 1786c9f4ff8a279e4dac1e8f385004d5fc253009
lottie-ios: e047b1d2e6239b787cc5e9755b988869cf190494
lottie-react-native: 13cd0c4782c3e6bb26bfa4cc2d08bfb84f6d1ab6
MultiplatformBleAdapter: 5a6a897b006764392f9cef785e4360f54fb9477d
MultiplatformBleAdapter: ea8bac405ec200d0ca9de0f89afef6f06fb2abbc
nanopb: a0ba3315591a9ae0a16a309ee504766e90db0c96
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
PasscodeAuth: 667f2bfb0e78f652c11db4793d8077c189ce300e
Expand Down Expand Up @@ -1870,7 +1872,7 @@ SPEC CHECKSUMS:
React-Mapbuffer: 84ea43c6c6232049135b1550b8c60b2faac19fab
react-native-adjust: 801fe33f0dc0097b0474f11d08572a89fa6602ce
react-native-biometrics: 352e5a794bfffc46a0c86725ea7dc62deb085bdc
react-native-ble-plx: f10240444452dfb2d2a13a0e4f58d7783e92d76e
react-native-ble-plx: c040d0123518e121bf4cda02061bf72644f68d15
react-native-config: 86038147314e2e6d10ea9972022aa171e6b1d4d8
react-native-fast-crypto: 5943c42466b86ad70be60d3a5f64bd22251e5d9e
react-native-flipper: c33a4995958ef12a2b2f8290d63bed7adeed7634
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
"react-native-android-location-services-dialog-box": "^2.8.2",
"react-native-animatable": "^1.3.3",
"react-native-biometrics": "^3.0.1",
"react-native-ble-plx": "2.0.3",
"react-native-ble-plx": "3.1.2",
"react-native-config": "1.5.1",
"react-native-easy-markdown": "^2.0.0",
"react-native-extra-dimensions-android": "^1.2.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@ledgerhq/errors": "workspace:^",
"@ledgerhq/hw-transport": "workspace:^",
"@ledgerhq/logs": "workspace:^",
"react-native-ble-plx": "2.0.3",
"react-native-ble-plx": "3.1.2",
"rxjs": "^7.8.1",
"uuid": "^9.0.1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export const remapError = (error: IOBleErrorRemap): IOBleErrorRemap => {

if (error instanceof BleError) {
if (
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
error.iosErrorCode === BleATTErrorCode.UnlikelyError ||
error.reason === "Peer removed pairing information"
) {
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@
"@commitlint/cli": "^17.4.2",
"@commitlint/config-conventional": "^17.6.5",
"@commitlint/prompt-cli": "^17.4.2",
"@ledgerhq/create-release-hash": "workspace:*",
"@ledgerhq/pnpm-utils": "workspace:*",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
"@ledgerhq/create-release-hash": "workspace:*",
"chalk": "^4.1.2",
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-json": "^3.1.0",
"eslint-plugin-prettier": "^5.0.1",
"@ledgerhq/pnpm-utils": "workspace:*",
"prettier": "^3.0.3",
"rimraf": "^4.4.1",
"turbo": "1.10.1",
Expand Down Expand Up @@ -177,7 +177,8 @@
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]"
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]"
},
"packageExtensions": {
"eslint-config-next@*": {
Expand Down
Binary file removed patches/[email protected]
Binary file not shown.
Loading

0 comments on commit 5c490c4

Please sign in to comment.