Skip to content

Latest commit

 

History

History
32 lines (26 loc) · 1.72 KB

architecture.md

File metadata and controls

32 lines (26 loc) · 1.72 KB

UI architecture

Press makes heavy usage of reactive code through-out the app. It uses RxJava on Android and Reaktive in shared code.

Screens use a reactive MVI design for abstracting testable code. Each screen has one presenter that consumes user interactions in the form of “events”, performs logic with the help of data repositories and emits UI updates back that can be rendered by the screen. UI updates have two types:

  1. UI content models, that describe the state of the layout (example).
  2. UI effects, that cannot be modeled as state. For e.g., updating a text field once or navigating to a new screen (example).

Here’s an sample from Android:

class HomeScreen : FrameLayout() {
  fun onAttachedToWindow() {
    // View#clicks() comes from RxBinding.
    val uiEvents = noteList.clicks()
      .map { note -> NoteClicked(note) }

    presenter.uiUpdates(uiEvents)
      .takeUntil(detachedFromWindow())
      .subscribe(::render)
  }
}

class HomePresenter {
  fun uiUpdates(events: Observable<HomeEvent>) {
    return events
      .ofType<NoteClicked>
      .map { note -> OpenNote(note.uuid) }
  }
}

Take a look at HomePresenter or EditorPresenter to understand them in detail.