Coder Social home page Coder Social logo

k1rakishou / composesubsamplingscaleimage Goto Github PK

View Code? Open in Web Editor NEW
25.0 2.0 4.0 13.99 MB

Partial port of https://github.com/davemorrissey/subsampling-scale-image-view library to Jetpack Compose.

License: GNU General Public License v3.0

Kotlin 100.00%
jetpack-compose image zoomable-images kotlin coroutines subsampling android

composesubsamplingscaleimage's Introduction

ComposeSubsamplingScaleImage

Sample

Early preview (expect bugs)

dependencies {
  implementation 'com.github.K1rakishou:ComposeSubsamplingScaleImage:96b909f63b'
}

Why?

The original SubsamplingScaleImageView doesn't fully work with compose when using it inside of the HorizontalPager/LazyRow (probably the most common use-case: image gallery), namely swiping left/right doesn't work because SubsamplingScaleImageView, internally, calls requestDisallowInterceptTouchEvent(true) (basically tells every parent view to stop handling motion events/cancel all gestures) right after the first pointer touches the screen which (from my understanding) cancels awaitDownAndSlop() (code below awaitFirstDownOnPass() is never called so I assume the whole scope is getting canceled) function inside of the Modifier.draggable() which is used by Modifier.scrollable() which is used by LazyRow which is used by HorizontalPager. Even tough SubsamplingScaleImageView calls requestDisallowInterceptTouchEvent(false) after it detects that it cannot process the gesture (touch slop checks), Compose doesn't restart the awaitPointerEventScope after requestDisallowInterceptTouchEvent(false) is called (since it then waits for all pointers to be up or canceled) so the gesture stops working. I don't know whether it's a bug or is just not handled yet.

Why Partial?

I don't plan on porting all the features of the original SubsamplingScaleImageView, only the stuff that I personally need. Feel free to fork it and add whatever you need.

What currently works?

  • Tap detection.
  • Long tap detection.
  • Zoom/pan with two fingers.
  • One finger zoom (double-tap then move finger up/down for zoom).
  • Quick zoom (double tap to zoom in/zoom out).
  • Bunch of configurable parameters like minScale, maxScale, minScaleType, animation durations, etc.
  • Store/restore last scale/position upon configuration change.

What doesn't work but is planned?

  • It's impossible to replace one image with another without recreating the whole ComposeSubsamplingScaleImage composable.
  • Paddings.
  • PanLimit (PAN_LIMIT_INSIDE, PAN_LIMIT_OUTSIDE).
  • Bitmap pooling.

composesubsamplingscaleimage's People

Contributors

k1rakishou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

composesubsamplingscaleimage's Issues

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.