Skip to content
/ mojito Public
forked from mikaelzero/mojito

微信、bilibili大图、长图、gif、视频、自定义view的转场效果,The transition effect of wechat, bilibili large image, long image, GIF, video and custom view

Notifications You must be signed in to change notification settings

52im/mojito

 
 

Repository files navigation

mojito Language Language Version Size

English

如果这个库帮助到了你,希望能够分享给你身边的人。

二维码下载体验

通过视频查看效果

SAMPLE VIDEO LINK

动图效果

开始


添加 dependencies

allprojects {
    repositories {
        maven { url 'https://dl.bintray.com/mikaelzero/maven'}
    }
}

implementation 'net.mikaelzero.mojito:core:VERSION'

//support long image and gif with Sketch
implementation 'net.mikaelzero.mojito:SketchImageFactory:VERSION'

//load with fresco
implementation 'net.mikaelzero.mojito:FrescoImageLoader:VERSION'
//load with glide
implementation 'net.mikaelzero.mojito:GlideImageLoader:VERSION'

初始化

// in your application
Mojito.initialize(
            GlideImageLoader.with(this),
            SketchImageLoadFactory()
        )

//or

//YourMojitoConfig:IMojitoConfig
Mojito.initialize(
            GlideImageLoader.with(this),
            SketchImageLoadFactory(),
            YourMojitoConfig()
        )

开始使用

Mojito.with(context)
    .urls(SourceUtil.getSingleImage())
    .views(singleIv)
    .start()

使用

RecyclerView

Mojito.with(context)
    .urls(SourceUtil.getNormalImages())
    .position(position)
    .views(recyclerView, R.id.srcImageView)
    .autoLoadTarget(false)
    .setProgressLoader(object : InstanceLoader<IProgress> {
        override fun providerInstance(): IProgress {
            return DefaultPercentProgress()
        }
    })
    .setOnMojitoListener(object : SimpleMojitoViewCallback() {
        override fun onLongClick(fragmentActivity: FragmentActivity?, view: View, x: Float, y: Float, position: Int) {
            Toast.makeText(context, "long click", Toast.LENGTH_SHORT).show()
        }

        override fun onClick(view: View, x: Float, y: Float, position: Int) {
            Toast.makeText(context, "tap click", Toast.LENGTH_SHORT).show()
            }
        })
    .setIndicator(NumIndicator())
    .start()

单个 View

 Mojito.with(context)
    .urls(SourceUtil.getSingleImage())
    .views(singleIv)
    .start()

无 View

 Mojito.with(context)
    .urls(SourceUtil.getNormalImages())
    .start()

视频 View or 视频/图片 混合View

Mojito.with(context)
    .urls(SourceUtil.getVideoImages(), SourceUtil.getVideoTargetImages())
    .setMultiTargetEnableLoader(object : MultiTargetEnableLoader {
        override fun providerEnable(position: Int): Boolean {
            return position != 1
        }
    })
    .setMultiContentLoader(object : MultiContentLoader {
        override fun providerLoader(position: Int): ImageViewLoadFactory {
            return if (position == 1) {
                ArtLoadFactory()
            } else {
                SketchImageLoadFactory()
            }
        }
    })
    .position(position)
    .views(recyclerView, R.id.srcImageView)
    .start()

Callback回调

 abstract class SimpleMojitoViewCallback : OnMojitoListener {
    // image click
    override fun onClick(view: View, x: Float, y: Float, position: Int) {

    }

    //image long press
    override fun onLongClick(fragmentActivity: FragmentActivity?, view: View, x: Float, y: Float, position: Int) {
    }

    //end of min image to max image 
    override fun onShowFinish(mojitoView: MojitoView, showImmediately: Boolean) {
    }

    //activity finish,backToMin,single click
    override fun onMojitoViewFinish() {
    }

    //when you drag your image 
    override fun onDrag(view: MojitoView, moveX: Float, moveY: Float) {
    }

    //the ratio of long image when you scroll
    override fun onLongImageMove(ratio: Float) {
    }
}

API

Name desc
url(src,target) 设置缩略图和原图url数据
position 点击的位置
views 1. recylclerView,imageViewId
2. single view
3. multi views
autoLoadTarget 默认为true,如果你设置了原图的url并且设置了autoLoadTarget(false)
你需要使用setFragmentCoverLoader来自定义view
setProgressLoader 当你设置了 autoLoadTarget false 才会生效
setIndicator 可以选择 NumIndicator 或者 CircleIndexIndicator
setActivityCoverLoader 自定义Activity的覆盖层view
setMultiContentLoader 如果使用视频和图片混合模式,需要设置 ImageViewLoadFactory

Thanks

sketch

BigImageViewer

About

微信、bilibili大图、长图、gif、视频、自定义view的转场效果,The transition effect of wechat, bilibili large image, long image, GIF, video and custom view

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 91.0%
  • Kotlin 9.0%