Giter VIP home page Giter VIP logo

slideback's Introduction

SlideBack

无需继承的Activity侧滑返回库 类全面屏返回手势效果 仿“即刻”侧滑返回


前情

最近一直在研究侧滑返回效果的实现,目前比较多的方案如下:

  1. 背景透明主题。问题是性能与神坑"Only fullscreen activities can request orientation"。
  2. 将上页ContentView绘制到当前页,侧滑时动画推入推出。(也许挺不错?)
  3. 类全面屏返回手势。即刻App的效果(下图)。

本库这里选择了方案3。

预览

即刻App 本库 Demo下载

使用

  • 引用类库 *请将last-version替换为最新版本号
	// 1.添加jitpack仓库
	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
	// 2.添加项目依赖(last-version替换为最新版本号)
	dependencies {
		implementation 'com.github.parfoismeng:slideback:last-version'
	}
  • 代码使用
// Kotlin
class SecondActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // 在需要滑动返回的Activity中注册
        SlideBack.register(this) {
            Toast.makeText(this, "SlideBack", Toast.LENGTH_SHORT).show()
        }
    }

    override fun onDestroy() {
        super.onDestroy()

        // onDestroy时记得解绑
        // 内部使用WeakHashMap,理论上不解绑也行,但最好还是手动解绑一下
        SlideBack.unregister(this)
    }
}

// Java
public class SecondActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // 在需要滑动返回的Activity中注册
        SlideBack.register(this, new SlideBackCallBack() {
            @Override
            public void onSlideBack() {
                Toast.makeText(SecondActivity.this, "SlideBack", Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        // onDestroy时记得解绑
        // 内部使用WeakHashMap,理论上不解绑也行,但最好还是手动解绑一下
        SlideBack.unregister(this);
    }
}

OJBK!So easy!

性能

附一张性能截图。可以看出来中间进行了很多次 onCreate & onDestory,最后内存和开始时一致:  MEMORY

分析

源码分析MD:Analysis.md

感谢

感谢 ChenTianSaber 的开源库 SlideBack掘金)提供的思路与源码

更新

  1. 添加大量注释 & 源码分析MD - 未更新版本
  2. 删除无用依赖,添加Java引用示例 - 1.0.2
  3. 检查警告,修改类名,更新README.md - 1.0.1
  4. 初版发布 - 1.0.0

计划

  1. 目前还是依赖了v7包,作用仅为@ColorInt和@Nullable约束,要不要保留呢?
  2. 提交个Kotlin版本(其实AS直接转换就行...)
  3. 看情况吧......

支持

劳烦各位大佬给个Star让我出去好装B行嘛!

slideback's People

Contributors

parfoismeng avatar

Watchers

James Cloos 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.