Giter Site home page Giter Site logo

anistn / compose-impression-tracker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from abema/compose-impression-tracker

0.0 0.0 0.0 132 KB

A simple and flexible library for tracking component impressions with Jetpack Compose

License: Apache License 2.0

Kotlin 100.00%

compose-impression-tracker's Introduction

Jetpack Compose Impression Tracker

Track Jetpack Compose component impressions in a simple and flexible way

Text(
  "text",
  Modifier.impression(
    key = item,
    impression = { key ->
      println("impressed:$key")
    })
)

Jetpack Compose Impression Tracker

Flexible

You can customize DefaultImpressionState's parameters.

val impressionState = remember {
  DefaultImpressionState(
    lifecycle = lifecycle,
    impressionDuration = 1000,
    checkInterval = 1000,
    visibleRatio = 0.5,
  )
}
Text(
  "text",
  Modifier.impression(
    key = item,
    impressionState = impressionState,
    impression = { key ->
      println("impressed:$key")
    })
)

You can implement your impression logic.

val impressionState = remember {
  object: ImpressionState {
    override val impressFlow: SharedFlow<Any>
      get() = TODO("write your logic!")

    override fun onLayoutCoordinatesChange(
      key: Any,
      size: IntSize,
      boundsRect: Rect,
      composeViewRect: Rect
    ) {
      TODO("write your logic!")
    }

    override fun onDispose(key: Any) {
      TODO("write your logic!")
    }
  }
}

You can share impression state by CompositionLocal

ProvideImpressionState(rememberDefaultImpressionState()) {
  Text(
    "text",
    Modifier.
    impression(
      key = "key",
      impression = { key ->
        println("impressed:$key")
      })
  )
}

compose-impression-tracker's People

Contributors

takahirom avatar

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.