All Projects → sellmair → Kompass

sellmair / Kompass

Licence: mit
Kotlin Multiplatform Router for Android and iOS

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Kompass

Goldmovies
👑 The GoldMovies is based on Kotlin, MVVM architecture, coroutines, dagger, koin, and material designs & animations.
Stars: ✭ 314 (-4.27%)
Mutual labels:  mvvm, mvvm-architecture
socket-chat
This project will help you build a chat app by using the Socket IO library.
Stars: ✭ 36 (-89.02%)
Mutual labels:  mvvm, mvvm-architecture
MVVM-Sample
Swift MVVM Sample project. Made with ReactiveCocoa, Swinject and Routers
Stars: ✭ 21 (-93.6%)
Mutual labels:  router, mvvm
Kotlinmultiplatform
Kotlin MultiPlatform App (Android, iOS, JVM & JS). MVVM/MVP - Kotlin MultiPlatform
Stars: ✭ 661 (+101.52%)
Mutual labels:  multiplatform, mvvm-architecture
Kotlin Android Mvvm Starter
Android Kotlin Starter is a starter project which implements MVVM Pattern.
Stars: ✭ 276 (-15.85%)
Mutual labels:  mvvm, mvvm-architecture
Ccc
💰 Currency Converter Calculator with power of Kotlin Multiplatform
Stars: ✭ 109 (-66.77%)
Mutual labels:  multiplatform, mvvm
TMDbMultiplatform
Step-by-step guide on Kotlin Multiplatform
Stars: ✭ 86 (-73.78%)
Mutual labels:  mvvm, mvvm-architecture
Barba
Create badass, fluid and smooth transition between your website's pages.
Stars: ✭ 9,372 (+2757.32%)
Mutual labels:  router, transition
Githubfollows
A demo project based on MVVM architecture and material design & animations.
Stars: ✭ 272 (-17.07%)
Mutual labels:  mvvm, mvvm-architecture
Android Mvp Mvvm Flytour
🔥🔥🔥 FlyTour是Android MVVM+MVP+Dagger2+Retrofit+RxJava+组件化+插件组成的双编码架构+双工程架构+双语言Android应用开发框架,通过不断的升级迭代该框架已经有了十个不同的版本,5.0之前工程架构采用gradle配置实现组件化,5.0之后的工程架构采用VirtualAPK实现了插件化,5.0之前采用Java编码实现,5.0之后采用Kotlin编码实现,编码架构由MVVM和MVP组成,工程架构和编码架构及编码语言开发者可根据自己具体的项目实际需求去决定选择使用,该框架是Android组件化、Android插件化、Android MVP架构、Android MVVM架构的集大成者,帮助你快速的搭建自己的App项目开发框架,以便把主要的精…
Stars: ✭ 2,948 (+798.78%)
Mutual labels:  mvvm, mvvm-architecture
Marshroute
Marshroute is an iOS Library for making your Routers simple but extremely powerful
Stars: ✭ 208 (-36.59%)
Mutual labels:  router, transition
Swinjectmvvmexample
An example to use Swinject in MVVM architecture with ReactiveCococa
Stars: ✭ 301 (-8.23%)
Mutual labels:  mvvm, mvvm-architecture
Visualizer
UI-Router state visualizer and transition visualizer
Stars: ✭ 205 (-37.5%)
Mutual labels:  router, transition
My Android Garage
A quick reference guide for Android development.
Stars: ✭ 66 (-79.88%)
Mutual labels:  transition, mvvm-architecture
Tieguanyin
Activity Builder.
Stars: ✭ 113 (-65.55%)
Mutual labels:  router, fragments
FindTaek
📦 내가 시킨 택배가 어디까지 왔는지 확인해보세요
Stars: ✭ 26 (-92.07%)
Mutual labels:  mvvm, mvvm-architecture
Jetpack Mvvm Scaffold
人生苦短,让脚手架为你节省时间。(目前作为《最佳实践》项目的 Dev 版来优先更新)
Stars: ✭ 239 (-27.13%)
Mutual labels:  mvvm, mvvm-architecture
React Router Page Transition
Highly customizable page transition component for your React Router
Stars: ✭ 531 (+61.89%)
Mutual labels:  router, transition
StackOverFlowApi
working with Stack OverFlow Api
Stars: ✭ 24 (-92.68%)
Mutual labels:  fragments, mvvm
Clean Mvvm Archcomponents
👽 Android app consuming Star Wars API.Built with clean architecture ,MVVM pattern, Koin , Coroutines + Flows ,Architecture Components, Data Binding , Firebase , Unit/UI Tests ,Motion Layout
Stars: ✭ 285 (-13.11%)
Mutual labels:  mvvm, mvvm-architecture

Kompass

A powerful Kotlin Multiplatform Router for Android and iOS


GitHub top language Build Status Bintray GitHub last commit Gitter

Support

I am happy to help you with any problem on gitter
Feel free to open any new issue!

What Kompass can do for you

  • Perfect fit for MVVM, MVI, MVP, MVX architectures
  • Powerful routing concept that targets multiple platforms like Android, JVM & iOS
  • Easy to use API's
  • Highly configurable implementations

Android

  • Flexible routing with fragments
  • Built in solution for passing arguments to fragments
  • Very easy support for transitions/animations
  • No XML configuration
  • Built in DSL to configure the FragmentRouter
  • Survives configuration changes
  • Can restore the "routing stack" after process death

What Kompass can't do for now

While the core module is currently built and published for multiple platforms (JVM, iOS), there are no default Router implementations for any other platforms than Android yet. Those are currently "work in progress". Kompass can still be used as a common API for routing by providing custom implementations of a Router for your platform!

Setup

Step 1: Add the repository

Artifacts are linked to jCenter. Add jCenter repository to your root build.gradle

build.gradle

  allprojects {
     repositories {
        jcenter()
     }
  }

Step 2: Add the dependency (Multiplatform)

build.gradle.kts

kotlin {
    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("io.sellmair:kompass-core:0.2.0-alpha.5")
            }
        }
        
        /* Optional Android module */
        val androidMain by getting {
            dependencies {
                implementation("io.sellmair:kompass-android:0.2.0-alpha.5")
            }
        }
    }
}

Step 2: Add the dependency (Android Only)

build.gradle.kts

dependencies {
    implementation("io.sellmair:kompass-android:0.2.0-alpha.4")
}

Optional Step 3: (Android: Highly encouraged) Enable Kotlin's Android extensions (with @Parcelize)

build.gradle.kts

plugins {
    // ...
    id("org.jetbrains.kotlin.android.extensions")
}

// ...

// Currently still necessary for @Parcelize annotation
androidExtensions {
    isExperimental = true
}

Usage

Example

I recommend having a look at the example app built with Kompass



Gif


Defining routes

Routes can easily be represented by data classes. Let's say your App has three routes that you might want to display: A LoginRoute, ContactListRoute and a ChatRoute:

sealed class AppRoute : Route, Parcelable

@Parcelize
class LoginRoute: AppRoute()

@Parcelize
data class ContactListRoute(val contacts: List<Contact>): AppRoute()

@Parcelize
data class ChatRoute(val contact: Contact): AppRoute() 

All the arguments necessary to display a certain route should be present in the route itself. The example above uses the @Parcelize feature from the Kotlin's Android extensions

Creating a router instance (Android)

A FragmentRouter for Android can be configured quite easily by using the built in DSL for configuration.

router = FragmentRouter {
            transitions {
                register(LoginToContactListTransition())
                register(ContactListToChatTransition())
            }
            routing {
                route<LoginRoute> { LoginFragment::class }
                route<ContactListRoute> { ContactListFragment::class }
                route<ChatRoute> { ChatFragment::class }
            }
        }

The above DSL shows two configurations:

  • transitions: configures animations/transitions that should be running when routing
  • routing: configures which Fragment should be displayed for a certain route

Setting up a router instance (Android)

A FragmentRouter needs a ViewGroup to place the fragments in. This can be setup like this:

class MainActivity : AppCompatActivity(), KompassFragmentActivity {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        router.setup(savedInstanceState, R.id.container)
    }


    override fun onBackPressed() {
        router.popRetainRootImmediateOrFinish()
    }

}

Please note: In order to call the setup method, one needs to either implement KomapssFragmentActivity or KompassFragment!

Routing (Simple push)

Let's assume that the user taps on a certain contact in the contact list displayed by the ContactListRoute:

class ContactListViewModel {
 
    private val router = TODO("Maybe use DI?")
 
    fun onContactClicked(contact: Contact) {
        router.push(ChatRoute(contact))
    }

}

The code above will push the ChatRoute onto the "routing stack" and results in the ChatFragment being shown. Popping the "routing stack" will result in the ContactListFragment being displayed again.

Routing (Replacing the current route)

Let's assume the user successfully logged into your app. This should result in the current LoginRoute being replaced by the ContactListRoute

class LoginViewModel {

    private val router = TODO("What about Dagger?")
    
    fun onLoginSuccessful(user: User) {
        router.replaceTopWith(ContactListRoute(user.contacts))
    }
}

Wrapping multiple instructions into one lambda block will bundle them to one single operation on the routing stack. So you could alternatively write something like

fun onLoginSuccessful(user: User) {
    router { pop().push(ContactListRoute(user.contacts)) }
}

Routing (Arbitrary)

Kompass supports arbitrary routing: A instruction to the router is nothing more than a function from a list of routes to a new list of routes. Let's say your app would like to remove all ChatRoute with a certain contact

fun removeContactFromStack(contact: Contact) {
     router {
        with(filter { it.route.contact == contact })
     }
     
     //or
     
     router.plainStackInstruction { filter { it.route.contact == contact } }
}

Receiving the current route inside a Fragment

Accessing the route from within the any Fragment implementation is easily done by conforming to the KompassFragment interface:

class ContactListFragment : Fragment(), KompassFragment {
   
    override val router: FragmentRouter<AppRoute> = TODO() 
   
    private val route: ContactListRoute by route()
    
    override fun onCreate(savedInstanceState: Bundle?) {
        val contacts = route.contacts 
        
       //...
    }

}

Fragment Transitions

In order to support animations (fragment transitions) when routing you just need to implement a FragmentTransition. Example: Your chat app should show a Slide transition when going from the ContactListFragment to the ChatFragment and back. Simply implement the transition, check for your constraints and apply the transitions to the fragment. It is also possible to apply generic constraints to your transition using the GenericFragmentTransition API.

class ContactListToChatTransition : FragmentTransition {
    @SuppressLint("RtlHardcoded")
    override fun setup(
        transaction: FragmentTransaction,
        exitFragment: Fragment, exitRoute: Route,
        enterFragment: Fragment, enterRoute: Route
    ) {
        if (exitFragment is ContactListFragment && enterFragment is ChatFragment) {
            exitFragment.exitTransition = Slide(Gravity.LEFT)
            enterFragment.enterTransition = Slide(Gravity.RIGHT)
        }

        if (exitFragment is ChatFragment && enterFragment is ContactListFragment) {
            exitFragment.exitTransition = Slide(Gravity.RIGHT)
            enterFragment.enterTransition = Slide(Gravity.LEFT)
        }
    }
}

After the transition is implemented, just add it to the configuration of the FragmentRouter like seen above!

FragmentRouter { 
    transitions {
        register(LoginToContactListTransition())
    }
}

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].