Skip to content

Commit d5d8244

Browse files
committed
- Update in Kotlin version to 1.6.10
- Changed components to use Kotlin DSL
1 parent 1370bad commit d5d8244

File tree

8 files changed

+539
-463
lines changed

8 files changed

+539
-463
lines changed

README.md

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ojaynico-kotlin-react-native
2-
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.ojaynico/ojaynico-kotlin-react-native/badge.svg)](https://search.maven.org/artifact/com.github.ojaynico/ojaynico-kotlin-react-native/1.1.7/pom)
3-
[![Kotlin](https://img.shields.io/badge/kotlin-1.6.0-blue.svg?logo=kotlin)](http://kotlinlang.org)
2+
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.ojaynico/ojaynico-kotlin-react-native/badge.svg)](https://search.maven.org/artifact/com.github.ojaynico/ojaynico-kotlin-react-native/1.1.9/pom)
3+
[![Kotlin](https://img.shields.io/badge/kotlin-1.6.10-blue.svg?logo=kotlin)](http://kotlinlang.org)
44
[![npm version](https://img.shields.io/npm/v/react.svg?style=flat)](https://www.npmjs.com/package/react)
55
[![npm version](https://img.shields.io/npm/v/react-native?color=brightgreen&label=npm%20package)](https://www.npmjs.com/package/react-native)
66
[![Kotlin JS IR supported](https://img.shields.io/badge/Kotlin%2FJS-IR%20supported-yellow)](https://kotl.in/jsirsupported)
@@ -32,16 +32,21 @@ repositories {
3232
}
3333

3434
dependencies {
35-
implementation("com.github.ojaynico:ojaynico-kotlin-react-native:1.1.7")
35+
implementation("com.github.ojaynico:ojaynico-kotlin-react-native:1.1.9")
3636
}
3737
```
3838

3939
### `Example of a react native app using the above wrapper`
4040

4141
```kotlin
42-
import ojaynico.kotlin.react.*
43-
import ojaynico.kotlin.react.native.AppRegistry
44-
import react.*
42+
import ojaynico.kotlin.react.native.api.AppRegistry
43+
import ojaynico.kotlin.react.native.api.Platform
44+
import ojaynico.kotlin.react.native.component.ScrollView
45+
import ojaynico.kotlin.react.native.component.StyleSheet
46+
import ojaynico.kotlin.react.native.component.Text
47+
import ojaynico.kotlin.react.native.component.View
48+
import react.FC
49+
import react.Props
4550

4651
val styles = StyleSheet.create(object {
4752
val body = object {
@@ -52,29 +57,28 @@ val styles = StyleSheet.create(object {
5257
val fontWeight = "600"
5358
val color = "#000"
5459
}
55-
}
60+
})
5661

57-
class App : RComponent<Props, State>() {
58-
override fun RBuilder.render() {
59-
scrollView {
60-
attrs.contentInsetAdjustmentBehavior = "automatic"
61-
62-
view {
63-
attrs.style = styles.body
62+
val App = FC<Props> {
63+
ScrollView {
64+
contentInsetAdjustmentBehavior = "automatic"
6465

65-
text("Welcome to Kotlin React Native") {
66-
style = styles.text
67-
}
66+
View {
67+
style = styles.body
68+
69+
Text {
70+
style = styles.text
71+
+"Welcome to Kotlin React Native"
6872
}
6973
}
7074
}
7175
}
7276

7377
fun main() {
7478
// For class components
75-
AppRegistry.registerComponent("MyApp") { App::class.js }
79+
//AppRegistry.registerComponent("MyApp") { App::class.js }
7680
// For functional components (Assume App is the functional component)
77-
// AppRegistry.registerComponent("MyApp") { App }
81+
AppRegistry.registerComponent("MyApp") { App }
7882

7983
// Code below will work if you have added react native web dependency to your project.
8084
// Visit how to set up react native web in your project for a detailed instruction.
@@ -87,6 +91,7 @@ fun main() {
8791
}
8892
```
8993

94+
## `NOTE: STILL UNDER DEVELOPMENT. USE ALTERNATIVE NAVIGATION`
9095
### `Example using Navigation`
9196

9297
```kotlin

build.gradle.kts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import org.jetbrains.kotlin.gradle.plugin.statistics.ReportStatisticsToElasticSearch.password
2+
13
plugins {
2-
kotlin("js") version "1.6.0"
4+
kotlin("js") version "1.6.10"
35
id("maven-publish")
46
id("io.codearte.nexus-staging") version "0.30.0"
57
signing
68
}
79

810
group = "com.github.ojaynico"
9-
version = "1.1.7"
11+
version = "1.1.9"
1012

1113
val artifactName = project.name
1214
val artifactGroup = project.group.toString()
@@ -30,7 +32,6 @@ val pomDeveloperEmail = "ojaynico@gmail.com"
3032

3133
repositories {
3234
mavenCentral()
33-
jcenter()
3435
}
3536

3637
kotlin {
@@ -41,10 +42,10 @@ kotlin {
4142
}
4243

4344
dependencies {
44-
implementation("org.jetbrains.kotlin-wrappers:kotlin-react:17.0.2-pre.274-kotlin-1.6.0")
45-
implementation("org.jetbrains.kotlin-wrappers:kotlin-extensions:1.0.1-pre.274-kotlin-1.6.0")
45+
implementation("org.jetbrains.kotlin-wrappers:kotlin-react:17.0.2-pre.294-kotlin-1.6.10")
46+
implementation("org.jetbrains.kotlin-wrappers:kotlin-extensions:1.0.1-pre.294-kotlin-1.6.10")
4647
implementation(npm("react", "17.0.2"))
47-
implementation(npm("react-native", "0.66"))
48+
implementation(npm("react-native", "0.67.2"))
4849
}
4950

5051
val sourcesJar by tasks.registering(Jar::class) {

src/main/kotlin/ojaynico/kotlin/react/Extensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
package ojaynico.kotlin.react
44

5-
import ojaynico.kotlin.react.native.AppRegistry
5+
import ojaynico.kotlin.react.native.api.AppRegistry
66
import react.Component
77

88
// Components

src/main/kotlin/ojaynico/kotlin/react/NativeBuilder.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package ojaynico.kotlin.react
22

33
import ojaynico.kotlin.react.native.*
4-
import react.RBuilder
5-
import react.RElementBuilder
64
import react.ReactNode
7-
import react.createElement
85

9-
fun RBuilder.view(handler: RElementBuilder<ViewProps>.() -> Unit) = child(View::class) {
6+
/*fun RBuilder.view(handler: RElementBuilder<ViewProps>.() -> Unit) = child(View::class) {
107
handler()
118
}
129
@@ -126,6 +123,6 @@ fun RBuilder.touchableNativeFeedback(handler: TouchableNativeFeedbackProps.() ->
126123
127124
fun RBuilder.inputAccessoryView(handler: InputAccessoryViewProps.() -> Unit) = child(InputAccessoryView::class) {
128125
attrs(handler)
129-
}
126+
}*/
130127

131128
typealias ComponentProvider = () -> dynamic
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package ojaynico.kotlin.react
22

3-
import ojaynico.kotlin.react.navigator.Navigator
4-
import ojaynico.kotlin.react.navigator.NavigatorProps
5-
import ojaynico.kotlin.react.navigator.Route
6-
import ojaynico.kotlin.react.navigator.RouteProps
7-
import react.RBuilder
8-
import react.RElementBuilder
9-
3+
/*
104
fun RBuilder.navigator(handler: RElementBuilder<NavigatorProps>.() -> Unit) = child(Navigator::class) {
115
handler()
126
}
137
148
fun RBuilder.route(handler: RElementBuilder<RouteProps>.() -> Unit) = child(Route) {
159
handler()
1610
}
11+
12+
fun ChildrenBuilder.nico(handler: NavigatorProps) = child(Navigator::class) {
13+
handler
14+
}*/

src/main/kotlin/ojaynico/kotlin/react/native/Api.kt renamed to src/main/kotlin/ojaynico/kotlin/react/native/api/Api.kt

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
@file:JsModule("react-native")
22
@file:Suppress("unused")
33

4-
package ojaynico.kotlin.react.native
4+
package ojaynico.kotlin.react.native.api
55

66
import ojaynico.kotlin.react.ComponentProvider
7+
import ojaynico.kotlin.react.native.component.*
78
import react.Component
9+
import react.FC
810
import react.Props
911
import react.State
1012
import kotlin.js.Promise
@@ -24,6 +26,8 @@ external class Alert: Component<Props, State> {
2426
}
2527
}
2628

29+
external val AnimatedView : FC<ViewProps>
30+
2731
external class Animated : Component<Props, State> {
2832

2933
class View : Component<ViewProps, State> {
@@ -330,3 +334,86 @@ external object AccessibilityInfo {
330334
fun addEventListener(eventName: String, handler: (args: dynamic) -> Unit): dynamic
331335
fun removeEventListener(eventName: String, handler: (args: dynamic) -> Unit)
332336
}
337+
338+
external object Image {
339+
fun getSize(uri: String, success: () -> Unit, failure: () -> Unit): dynamic
340+
fun getSizeWithHeaders(uri: String, headers: dynamic, success: () -> Unit, failure: () -> Unit): dynamic
341+
fun prefetch(uri: String): dynamic
342+
fun abortPrefetch(requestId: Number): dynamic
343+
fun queryCache(vararg urls: String): dynamic
344+
fun resolveAssetSource(source: dynamic): dynamic
345+
}
346+
347+
external object TextInput {
348+
fun focus()
349+
fun blur()
350+
fun clear()
351+
fun isFocused(): dynamic
352+
}
353+
354+
external object FlatList {
355+
fun scrollToEnd(params: dynamic)
356+
fun scrollToIndex(params: dynamic)
357+
fun scrollToItem(params: dynamic)
358+
fun scrollToOffset(params: dynamic)
359+
fun recordInteraction()
360+
fun flashScrollIndicators()
361+
fun getNativeScrollRef()
362+
fun getScrollResponder()
363+
fun getScrollableNode()
364+
}
365+
366+
external object ScrollView {
367+
fun flashScrollIndicators()
368+
fun scrollTo(vararg options: dynamic)
369+
fun scrollToEnd(vararg options: dynamic)
370+
fun scrollWithoutAnimationTo(y: dynamic, x: dynamic)
371+
}
372+
373+
external object SectionList {
374+
fun scrollToLocation(params: dynamic)
375+
fun recordInteraction()
376+
fun flashScrollIndicators()
377+
}
378+
379+
external object StatusBar {
380+
fun popStackEntry(entry: dynamic): dynamic
381+
fun pushStackEntry(entry: dynamic): dynamic
382+
fun replaceStackEntry(entry: dynamic, props: dynamic): dynamic
383+
fun setBackgroundColor(color: String, animated: Boolean)
384+
fun setBarStyle(style: dynamic, animated: Boolean)
385+
fun setHidden(hidden: Boolean, animation: dynamic)
386+
fun setNetworkActivityIndicatorVisible(visible: Boolean)
387+
fun setTranslucent(translucent: Boolean)
388+
}
389+
390+
external object TouchableOpacity {
391+
fun setOpacityTo(value: Number, duration: Number)
392+
}
393+
394+
external object VirtualizedList {
395+
fun scrollToEnd(params: dynamic)
396+
fun scrollToIndex(params: dynamic)
397+
fun scrollToItem(params: dynamic)
398+
fun scrollToOffset(params: dynamic)
399+
fun recordInteraction()
400+
fun flashScrollIndicators()
401+
fun getScrollRef()
402+
fun getScrollResponder()
403+
fun getScrollableNode()
404+
fun setNativeProps(params: dynamic)
405+
fun getChildContext() : dynamic
406+
fun hasMore(): Boolean
407+
}
408+
409+
external object DrawerLayoutAndroid {
410+
fun closeDrawer()
411+
fun openDrawer()
412+
}
413+
414+
external object TouchableNativeFeedback {
415+
fun SelectableBackground(rippleRadius: Number)
416+
fun SelectableBackgroundBorderless(rippleRadius: Number)
417+
fun Ripple(color: String, borderless: Boolean, rippleRadius: Number)
418+
fun canUseNativeForeground()
419+
}

0 commit comments

Comments
 (0)