build a browser by kotlin colin lee sebastian kaspari
play

BUILD A BROWSER BY KOTLIN COLIN LEE SEBASTIAN KASPARI @colinmlee - PowerPoint PPT Presentation

BUILD A BROWSER BY KOTLIN COLIN LEE SEBASTIAN KASPARI @colinmlee @Anti_Hype Copenhagen Denmark Feature Session Toolbar Downloads Contextmenu Customtabs Findinpage Webnotifications Reader View Search Sync Prompts Sendtab QR ...


  1. BUILD A BROWSER BY KOTLIN COLIN LEE SEBASTIAN KASPARI @colinmlee @Anti_Hype Copenhagen Denmark

  2. Feature Session Toolbar Downloads Contextmenu Customtabs Findinpage Webnotifications Reader View Search Sync Prompts Sendtab QR ... Browser Toolbar Engine-System Engine-Gecko Search Tabstray Menu ... Concept Engine Toolbar Storage Fetch Push Tabstray ... UI Service Support Lib Autocomplete ... ... ... State Crash ...

  3. Agenda ● Why? ● How? ● Live code a browser! ● Syntactic Sugar

  4. Why?

  5. Firefox for Android

  6. Firefox for Android Focus for Android

  7. Firefox for Android Firefox Rocket Firefox Lite Focus for Android

  8. Firefox for Android Firefox Rocket Firefox Lite Focus for Android Firefox for Fire TV Firefox for Echo Show

  9. Firefox for Android ? Firefox Rocket Firefox Lite Focus for Android ? Firefox for Fire TV ? Firefox for Echo Show

  10. This does not scale! Firefox for Android ? Firefox Rocket Firefox Lite Focus for Android ? Firefox for Fire TV ? Firefox for Echo Show

  11. Goals ● Share code between our apps ● Reduce the maintenance overhead ● Clear architecture boundaries ● Make it easier and faster to build new or experimental products.

  12. Solution: Build independent, reusable components to share code between existing projects and build new apps faster.

  13. Components? ● Independent open-source Android libraries ● “Android First” extensible application architecture ● Minimal cross-component and third-party dependencies ● Customizable and pluggable ● Distributed as AARs via a Maven repository

  14. Components? 100% Kotlin

  15. Components? 100% Kotlin Well, and some Rust

  16. How?

  17. Browser Engine

  18. HTML CSS Browser Engine JS

  19. Browser Engine WebView GeckoView Servo ...

  20. GeckoView

  21. GeckoView ● App developer in control of updates. Only one version needs to be supported. No surprises. ○ ● Multiprocess ● Separation of session (tab) and view ● Private mode ● WebExtensions ● Tracking Protection

  22. Engine Components browser-engine-system concept-engine browser-engine-gecko ...

  23. Toolbar

  24. Engine Components browser-toolbar concept-toolbar ...

  25. Done?

  26. What else?

  27. feature-media feature-downloads browser-contextmenu feature-readerview browser-awesomebar feature-downloads

  28. Feature Session Toolbar Downloads Contextmenu Customtabs Findinpage Webnotifications Reader View Search Sync Prompts Sendtab QR ... Browser Toolbar Engine-System Engine-Gecko Search Tabstray Menu ... Concept Engine Toolbar Storage Fetch Push Tabstray ... UI Service Support Lib Autocomplete ... ... ... State Crash ...

  29. LIVE CODING

  30. Syntactic Sugar Mozilla ❤ Kotlin

  31. null, null?, null!! Explicit nullability

  32. Handling state

  33. lib-state Store & State Store State

  34. data classes Modeling State data class BrowserState( val tabs: List<TabSessionState> = emptyList (), val selectedTabId: String? = null, val customTabs: List<..> = emptyList (), val extensions: Map<..> = emptyMap () ) : State

  35. lib-state Observing state Store State observes State Component / App

  36. lib-state Observing state @CheckResult(suggest = "observe") @Synchronized fun observeManually( observer: Observer<S> ): Subscription<S, A> { // .. }

  37. lib-state Observing state val subscription = store.observeManually { state -> // .. } subscription.unsubscribe()

  38. Extension functions Iterating on API @MainThread fun <..> Store<S, A>.observe( owner: LifecycleOwner, observer: Observer<S> ) { // .. }

  39. Extension functions Iterating on API @MainThread fun <..> Store<S, A>.observe( view: View, observer: Observer<S> ) { // .. }

  40. lib-state Dispatching actions Store State observes Action State dispatches Component / App

  41. Sealed classes Modeling Actions sealed class TabListAction : BrowserAction() { data class AddTabAction( val tab: TabSessionState, val select: Boolean = false ) : TabListAction() data class SelectTabAction( val tabId: String ) : TabListAction() // .. }

  42. lib-state Inside the store Store Action Reducer State State

  43. Functions & Sealed classes Reducing state fun reduce( state: BrowserState, action: TabListAction ): BrowserState { return when (action) { is TabListAction.AddTabAction -> { .. } is TabListAction.SelectTabAction -> { .. } // .. } }

  44. data classes Creating a new state val newState = state .copy( selectedTabId = "some-other-tab" )

  45. Type aliases Observing state typealias Observer<S> = (S) -> Unit typealias Reducer<S, A> = (S, A) -> S

  46. Channels & Flow

  47. Channel Observing state sequentially @ExperimentalCoroutinesApi @MainThread fun <..> Store<S, A>.channel( owner: LifecycleOwner = ProcessLifecycleOwner.get() ): ReceiveChannel<S> { // .. }

  48. Flow Observing state @ExperimentalCoroutinesApi @MainThread fun <..> Store<S, A>.flow( owner: LifecycleOwner? = null ): Flow<S> { // .. }

  49. “Scoped flow” Observing state @ExperimentalCoroutinesApi @MainThread fun <..> Store<S, A>.flowScoped( owner: LifecycleOwner? = null, block: suspend (Flow<S>) -> Unit ): CoroutineScope { // .. }

  50. Operators for dealing with state updates

  51. Flow operators Only update UI if the state has changed fun <T> Flow<T>.ifChanged(): Flow<T> store . flow () . map { state -> state. selectedTab .title } . ifChanged () . collect { title -> // .. }

  52. Flow operators Only update UI if state changed partially fun <T, R> Flow<T>.ifChanged( transform: (T) -> R ): Flow<T> store . flow () . ifChanged { state -> state. selectedTab .title } . collect { state -> // .. }

  53. Flow operators fun <T, R> Flow<List<T>>.filterChanged( transform: (T) -> R ): Flow<T> store . flow () . map { state -> state.tabs } . filterChanged { tab -> tab.title } . collect { tab -> // .. }

  54. https://mozac.org https://mozilla.github.io/geckoview https://mozilla.github.io/application-services/ https://github.com/mozilla-mobile/

  55. THANK YOU AND REMEMBER TO VOTE Colin Lee @colinmlee Sebastian Kaspari @Anti_Hype #KotlinConf

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend