All Projects → ojaynico → ojaynico-kotlin-react-native

ojaynico / ojaynico-kotlin-react-native

Licence: MIT License
Kotlin Wrapper for React Native Components and APIs

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to ojaynico-kotlin-react-native

static-code-analysis-plugin
A plugin to simplify Static Code Analysis on Gradle. Not restricted to, but specially useful, in Android projects, by making sure all analysis can access the SDK classes.
Stars: ✭ 36 (+157.14%)
Mutual labels:  gradle
Android-GradlePlugin-Demo
Android Studio 自定义 Gradle Plugin
Stars: ✭ 27 (+92.86%)
Mutual labels:  gradle
TwitterApiKit
Twitter's API v2 Objectified. This will save you time from creating data objects to access twitter's API v2. This library is supported on Gradle, Maven, Java, Kotlin, and Android projects.
Stars: ✭ 23 (+64.29%)
Mutual labels:  gradle
OkOne
基于okhttp库的网络性能优化框架
Stars: ✭ 88 (+528.57%)
Mutual labels:  gradle
spring-boot-angular2-starter
Starter application. Spring Boot, Angular 2, TypeScript, Gulp, Gradle, SCSS.
Stars: ✭ 35 (+150%)
Mutual labels:  gradle
sonatype-publish-plugin
Gradle Plugin for publishing artifacts to Sonatype and Nexus
Stars: ✭ 17 (+21.43%)
Mutual labels:  gradle
idiomatic-gradle
How do I idiomatically structure a large build with Gradle 7.2+?
Stars: ✭ 129 (+821.43%)
Mutual labels:  gradle
javacard-gradle-template
JavaCard project template for building CAP and running JCardSim with gradle + coverage
Stars: ✭ 27 (+92.86%)
Mutual labels:  gradle
SetupBuilder
Gradle plugin for building setups for different platforms.
Stars: ✭ 75 (+435.71%)
Mutual labels:  gradle
kotlin multiplatform gradle demo
My attempt to get Gradle to work with multiplatform Kotlin while using subprojects.
Stars: ✭ 24 (+71.43%)
Mutual labels:  gradle
connection checker
Android library for checking the internet connectivity of a device.
Stars: ✭ 26 (+85.71%)
Mutual labels:  gradle
Entitas-Java
Entity Component System (ECS) in Java 8
Stars: ✭ 37 (+164.29%)
Mutual labels:  gradle
spring-boot-microservice-best-practices
Best practices and integrations available for Spring Boot based Microservice in a single repository.
Stars: ✭ 139 (+892.86%)
Mutual labels:  gradle
gatling-gradle-plugin-demo
Showcase of the Gatling Plugin for Gradle
Stars: ✭ 17 (+21.43%)
Mutual labels:  gradle
AndroidDevTools
收集整理Android开发所需的Android SDK、开发中用到的工具、Android开发教程、Android设计规范,免费的设计素材等。
Stars: ✭ 7,284 (+51928.57%)
Mutual labels:  gradle
base-android
🏗 Collection of common utility classes and setup I use in my Android apps
Stars: ✭ 47 (+235.71%)
Mutual labels:  gradle
openjfx-docs
Getting started guide for JavaFX 11
Stars: ✭ 70 (+400%)
Mutual labels:  gradle
XTCP
一个便捷的TCP消息包拼装和解析框架
Stars: ✭ 20 (+42.86%)
Mutual labels:  gradle
RocketXPlugin
🔥🔥 android 端编译加速插件🚀 自动识别未改动 module 并在编译流程中替换为 aar ,只编译改动模块,加速 Android apk 的编译速度。
Stars: ✭ 408 (+2814.29%)
Mutual labels:  gradle
androidScientificCalculator
➕An elegant feature-packed scientific calculator app for Android. Published on the Google Play Store.
Stars: ✭ 23 (+64.29%)
Mutual labels:  gradle

ojaynico-kotlin-react-native

Maven Central Kotlin npm version npm version Kotlin JS IR supported

Kotlin Wrappers for React Native Components and APIs

Available components: All react native components are available in this wrapper. Check them out using the URL below:

https://reactnative.dev/docs/components-and-apis

Available APIs: All react native APIs are available in this wrapper. Check them out using the URL below:

https://reactnative.dev/docs/accessibilityinfo

How to use the wrapper?

Use the cli tool below to generate a new Kotlin React Native application.

https://github.com/ojaynico/create-ojaynico-krn

Proceed to the next step after generating the project.

In your react native application shared module (a kotlin gradle project), update your gradle file to include the following in the respective blocks.

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    implementation("com.github.ojaynico:ojaynico-kotlin-react-native:1.1.7")
}

Example of a react native app using the above wrapper

import ojaynico.kotlin.react.*
import ojaynico.kotlin.react.native.AppRegistry
import react.*

val styles = StyleSheet.create(object {
    val body = object {
            val backgroundColor = "#FFF"
    }
    val text = object {
            val fontSize = 24
            val fontWeight = "600"
            val color = "#000"
    }
}

class App : RComponent<Props, State>() {
    override fun RBuilder.render() {
        scrollView {
            attrs.contentInsetAdjustmentBehavior = "automatic"
            
            view {
                attrs.style = styles.body

                text("Welcome to Kotlin React Native") {
                    style = styles.text
                }
            }
        }
    }
}

fun main() {
    // For class components
    AppRegistry.registerComponent("MyApp") { App::class.js }
    // For functional components (Assume App is the functional component)
    // AppRegistry.registerComponent("MyApp") { App }

    // Code below will work if you have added react native web dependency to your project. 
    // Visit how to set up react native web in your project for a detailed instruction.
    // An example project using react native web is in the link at the end of this document.
    if (Platform.OS == "web") {
        AppRegistry.runApplication("MyApp", json {
            rootTag = document.getElementById("root")
        })
    }
}

Example using Navigation

import ojaynico.kotlin.react.*
import ojaynico.kotlin.react.native.AppRegistry
import ojaynico.kotlin.react.native.Platform
import kotlinx.browser.document
import react.*

val Menu = functionComponent<MenuProps> { props ->
    view {
        this.attrs.style = json {
            flex = 1
            backgroundColor = "white"
            marginRight = "90%"
        }

        button {
            title = "Screen Two"
            onPress = {
                // props being passed through a json object
                // NOTE: An interface with the props below have to be defined and used by ScreenTwo component
                props.navigator.push("ScreenTwo", json {
                    name = "Nicodemus Ojwee"
                    age = 25
                    school = "Namilyango College"
                })
            }
        }
        button {
            title = "Screen Three"
            onPress = {
                props.navigator.push("ScreenThree", json {  })
            }
        }

    }
}

val App = functionComponent<Props> {
    navigator {
        this.attrs {
            // Side Menu (from above) is passed as functional component prop
            // Using asDynamic() for now till the next update
            asDynamic().sideMenu = Menu
            asDynamic().menuPosition = "left"
        }
        route {
            this.attrs {
                name = "ScreenOne"
                component = ScreenOne
            }
        }
        // pathVariables has to be defined as below if you plan to pass props in react native web
        // pathVariables names are supposed to be similar and in the order in which you have defined your props interface in ScreenTwoProps
        route {
            this.attrs {
                name = "ScreenTwo"
                component = ScreenTwo
                pathVariables = "name/age/school"
            }
        }
        route {
            this.attrs {
                name = "ScreenThree"
                component = ScreenThree
            }
        }
    }
}

val ScreenOne = functionComponent<NavigationProps> { props ->
    view {
        this.attrs.style = json {
            backgroundColor = "#59C9A5"
            flex = 1
        }

        button {
            title = "Menu"
            onPress = {
                props.navigator.showMenu()
            }
        }

        button {
            title = "Screen Two"
            onPress = {
                // props being passed through a json object
                // NOTE: An interface with the props below have to be defined and used by ScreenTwo component
                props.navigator.push("ScreenTwo", json {
                    name = "Nicodemus Ojwee"
                    age = 25
                    school = "Namilyango College"
                })
            }
        }

        button {
            title = "Pop"
            onPress = {
                props.navigator.pop()
            }
        }
    }
}

// If using web, the props defined in the interface below have to be defined as pathVariables
// in the route {} function above in App component and they have to follow the order.
external interface ScreenTwoProps : NavigationProps {
    var name: String
    var age: Int
    var school: String
}

val ScreenTwo = functionComponent<ScreenTwoProps> { props ->
    view {
        this.attrs.style = json {
            backgroundColor = "#23395B"
            flex = 1
            alignItems = "center"
            justifyContent = "center"
        }

        button {
            title = "Screen Three"
            onPress = {
                props.navigator.push("ScreenThree", json {  })
            }
        }

        button {
            title = "Pop"
            onPress = {
                props.navigator.pop()
            }
        }

        text("Name is " + props.name) {
            this.attrs {
                style = json {
                    color = "white"
                }
            }
        }

        text("Age is " + props.age) {
            this.attrs {
                style = json {
                    color = "white"
                }
            }
        }

        text("School is " + props.school) {
            this.attrs {
                style = json {
                    color = "white"
                }
            }
        }
    }
}

val ScreenThree = functionComponent<NavigationProps> { props ->
    view {
        this.attrs.style = json {
            backgroundColor = "#B9E3C6"
            flex = 1
            alignItems = "center"
            justifyContent = "center"
        }

        button {
            title = "Pop"
            onPress = {
                props.navigator.pop()
            }
        }
    }
}

fun main() {
    AppRegistry.registerComponent("MyApp") { App }

    // Code below will work if you have added react native web dependency to your project. 
    // Visit how to set up react native web in your project for a detailed instruction.
    // An example project using react native web is in the link at the end of this document.
    if (Platform.OS == "web") {
        AppRegistry.runApplication("MyApp", json {
            rootTag = document.getElementById("root")
        })
    }
}

NOTE: In the main function, MyApp should be the same as the name of the app directory

A fully set up and working example can be found in the repository below.

https://github.com/ojaynico/KotlinReactNativeApp

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].