Skip to content
Merged
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
27 changes: 24 additions & 3 deletions lib/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ def safeExtGetFallbackLowerBound(prop, fallback) {
Math.max(safeExtGet(prop,fallback),fallback)
}

def DEFAULT_COMPILE_SDK_VERSION = 30
def DEFAULT_COMPILE_SDK_VERSION = 33
def DEFAULT_MIN_SDK_VERSION = 21
def DEFAULT_TARGET_SDK_VERSION = 30
def DEFAULT_TARGET_SDK_VERSION = 33
def DEFAULT_KOTLIN_VERSION = "1.5.31"
def DEFAULT_KOTLIN_STDLIB = 'kotlin-stdlib-jdk8'
def kotlinVersion = safeExtGet("RNNKotlinVersion", DEFAULT_KOTLIN_VERSION)
def kotlinStdlib = safeExtGet('RNNKotlinStdlib',DEFAULT_KOTLIN_STDLIB )
def kotlinCoroutinesCore = safeExtGet('RNNKotlinCoroutinesCore', '1.5.2')
android {
compileSdkVersion safeExtGetFallbackLowerBound('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)

buildToolsVersion = "33.0.0"
defaultConfig {
minSdkVersion safeExtGetFallbackLowerBound('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGetFallbackLowerBound('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
Expand Down Expand Up @@ -167,6 +167,27 @@ List reactNativeVersionComponents(rnPackageJsonFile) {
return reactNativeVersion.tokenize('-')[0].tokenize('.')
}

task installBuildToolsAndRenameD8IfNeeded {
def buildToolsVersion = android.getBuildToolsVersion()
def sdkDir = android.sdkDirectory
def buildToolsDir = new File(sdkDir, "/build-tools/" + buildToolsVersion)

if (!buildToolsDir.exists()) {
def command = sdkDir.absolutePath + "/cmdline-tools/latest/bin/sdkmanager build-tools;" + buildToolsVersion
command.execute().waitForProcessOutput(System.out, System.err)
}

def d8File = new File(buildToolsDir, "d8")
def dxFile = new File(buildToolsDir, "dx")
d8File.renameTo(dxFile)

def buildToolsLibDir = new File(buildToolsDir, "lib")
d8File = new File(buildToolsLibDir, "d8.jar")
dxFile = new File(buildToolsLibDir, "dx.jar")
d8File.renameTo(dxFile)
}
build.dependsOn installBuildToolsAndRenameD8IfNeeded

dependencies {

implementation "androidx.core:core-ktx:1.6.0"
Expand Down
3 changes: 2 additions & 1 deletion lib/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.reactnativenavigation">
xmlns:tools="http://schemas.android.com/tools"
package="com.reactnativenavigation">

<application>
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.reactnativenavigation.viewcontrollers.modal.ModalStack;
import com.reactnativenavigation.viewcontrollers.navigator.Navigator;

import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
Expand All @@ -47,6 +48,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
);
navigator.bindViews();
getReactGateway().onActivityCreated(this);
setBackPressedCallback();
}

@Override
Expand Down Expand Up @@ -103,11 +105,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
getReactGateway().onActivityResult(this, requestCode, resultCode, data);
}

@Override
public void onBackPressed() {
getReactGateway().onBackPressed();
}

@Override
public boolean onKeyUp(final int keyCode, final KeyEvent event) {
return getReactGateway().onKeyUp(this, keyCode) || super.onKeyUp(keyCode, event);
Expand Down Expand Up @@ -152,4 +149,14 @@ protected void addDefaultSplashLayout() {
public void onCatalystInstanceDestroy() {
runOnUiThread(() -> navigator.destroyViews());
}

private void setBackPressedCallback() {
OnBackPressedCallback callback = new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
getReactGateway().onBackPressed();
}
};
getOnBackPressedDispatcher().addCallback(this, callback);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,4 @@ public ReactGateway getReactGateway() {
public void setNavigator(Navigator navigator) {
this.navigator = navigator;
}

@Override
public void onBackPressed() {
super.onBackPressed();
}
}
4 changes: 2 additions & 2 deletions playground/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ buildscript {
kotlinVersion = "1.5.31"
RNNKotlinVersion = kotlinVersion
detoxKotlinVersion = kotlinVersion
compileSdkVersion = 31
buildToolsVersion = "30.0.2"
compileSdkVersion = 33
buildToolsVersion = "31.0.0"
minSdkVersion = 21
targetSdkVersion = 31
}
Expand Down