Git Product home page Git Product logo

Comments (3)

Kpeved avatar Kpeved commented on June 1, 2024 1

@ichenhe thanks for your feedback and proposal. That request makes total sense. We're working on bringing rotary support by default to Compose for WearOS in AndroidX, so this will be very useful.
What we have to do is to align this api with similar apis regarding nested scroll support.

from horologist.

yschimke avatar yschimke commented on June 1, 2024

Cc @Kpeved in case you have thoughts

from horologist.

ichenhe avatar ichenhe commented on June 1, 2024

@Kpeved Here's my basic idea:

To support nested scrolling, we must implement the following:

  • Know the scrolling axis that can not be infered from the ScrollableState.
  • Have a NestedScrollDispatcher to dispatch the event.

Parameter

A parameter can be introduced to allow developer to specify the scroll axis and to provide their own NestedScrollDispatcher if needed.

Example
data class NestedScrollOptions (
    val axis: NestedScrollAxis,
    val dispatcher: NestedScrollDispatcher = NestedScrollDispatcher()
)

// public api
public fun Modifier.rotaryWithScroll(
    scrollableState: ScrollableState,
    nestedScrollOptions: NestedScrollOptions? = null,
    // others...
)

Dispatch

  1. Make RotaryInputNode extend DelegatingNode and register a delegate node: nestedScrollModifierNode(). The NestedScrollConnection here is meaningless so an empty implementation can be used.

    Example
    private class RotaryInputNode(
      var rotaryScrollHandler: RotaryScrollHandler,
      var nestedScrollDispatcher: NestedScrollDispatcher,
    ) : RotaryInputModifierNode, DelegatingNode() {
      init {
          val conn = object : NestedScrollConnection {}
          delegate(nestedScrollModifierNode(conn, dispatcher = nestedScrollDispatcher))
      }
    }
  2. Modify the RotaryScrollBehavior to dispatch nested scroll event.

    Example
     // RotaryScrollBehavior
    suspend fun handleEvent(targetValue: Float) {
        scrollAnimation.animateTo() {
            var consumed = dispatcher.dispatchPreScroll(Offset(0f, delta), NestedScrollSource.Wheel).y
            consumed += scrollBy(delta - consumed)
            dispatcher.dispatchPostScroll(
                Offset(0f, consumed),
                Offset(0f, delta - consumed),
                NestedScrollSource.Wheel
            )
        }
    }

from horologist.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.