Skip to content

Commit 32f1367

Browse files
committed
add kotlin example
1 parent dcba832 commit 32f1367

39 files changed

+784
-0
lines changed

example/kotlin/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild

example/kotlin/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>kotlin</name>
4+
<comment>Project kotlin created by Buildship.</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
connection.project.dir=
2+
eclipse.preferences.version=1

example/kotlin/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

example/kotlin/app/build.gradle

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
apply plugin: 'com.android.application'
2+
3+
apply plugin: 'kotlin-android'
4+
5+
apply plugin: 'kotlin-android-extensions'
6+
7+
project.ext.react = [
8+
entryFile: "example/index.js"
9+
]
10+
11+
apply from: "../../../node_modules/react-native/react.gradle"
12+
13+
android {
14+
compileSdkVersion rootProject.ext.compileSdkVersion
15+
16+
sourceSets {
17+
main.java.srcDirs += 'build/generated/rncli/src/main/java'
18+
}
19+
20+
defaultConfig {
21+
applicationId "com.callstack.kotlinexample"
22+
minSdkVersion rootProject.ext.minSdkVersion
23+
targetSdkVersion rootProject.ext.targetSdkVersion
24+
versionCode 1
25+
versionName "1.0"
26+
}
27+
28+
buildTypes {
29+
release {
30+
minifyEnabled false
31+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
32+
}
33+
}
34+
}
35+
36+
dependencies {
37+
implementation fileTree(dir: 'libs', include: ['*.jar'])
38+
implementation "com.facebook.react:react-native:+"
39+
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
40+
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
41+
implementation 'androidx.appcompat:appcompat:1.1.0-beta01'
42+
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
43+
implementation 'org.webkit:android-jsc:+'
44+
}
45+
46+
apply from: file("../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle");
47+
applyNativeModulesAppBuildGradle(project, "../..")

example/kotlin/app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.callstack.kotlinexample
2+
3+
import android.support.test.InstrumentationRegistry
4+
import android.support.test.runner.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getTargetContext()
22+
assertEquals("com.callstack.kotlinexample", appContext.packageName)
23+
}
24+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
3+
<application android:usesCleartextTraffic="true" tools:targetApi="28" />
4+
</manifest>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.callstack.kotlinexample">
4+
5+
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
8+
9+
<application
10+
android:name=".MainApplication"
11+
android:allowBackup="true"
12+
android:icon="@mipmap/ic_launcher"
13+
android:label="@string/app_name"
14+
android:roundIcon="@mipmap/ic_launcher_round"
15+
android:supportsRtl="true"
16+
android:theme="@style/AppTheme">
17+
<activity android:name=".MainActivity">
18+
<intent-filter>
19+
<action android:name="android.intent.action.MAIN"/>
20+
<category android:name="android.intent.category.LAUNCHER"/>
21+
</intent-filter>
22+
</activity>
23+
<activity android:name=".ReactNativeFragmentActivity"/>
24+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
25+
<activity android:name="com.callstack.reactnativebrownfield.ReactNativeActivity"/>
26+
</application>
27+
28+
</manifest>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.callstack.kotlinexample
2+
3+
import android.content.Intent
4+
import android.os.Bundle
5+
import androidx.appcompat.app.AppCompatActivity
6+
import com.callstack.reactnativebrownfield.ReactNativeActivity
7+
import android.view.View
8+
9+
10+
class MainActivity : AppCompatActivity() {
11+
override fun onCreate(savedInstanceState: Bundle?) {
12+
super.onCreate(savedInstanceState)
13+
setContentView(R.layout.activity_main)
14+
supportActionBar!!.hide()
15+
}
16+
17+
fun startReactNative(view: View) {
18+
val intent = ReactNativeActivity.createReactActivityIntent(
19+
this,
20+
"ReactNative"
21+
)
22+
startActivity(intent)
23+
}
24+
25+
fun startReactNativeFragment(view: View) {
26+
val intent = Intent(this, ReactNativeFragmentActivity::class.java)
27+
startActivity(intent)
28+
}
29+
}

0 commit comments

Comments
 (0)