All Projects → yuanhoujun → Snake

yuanhoujun / Snake

Licence: apache-2.0
使用Snake,Android也可以轻松实现类iOS侧滑返回效果

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Snake

Pageslider
朋友圈广告 - 移动端滑屏翻页插件
Stars: ✭ 442 (-26.94%)
Mutual labels:  weixin
Planmaster
套餐助手:手机套餐对比选购小程序
Stars: ✭ 487 (-19.5%)
Mutual labels:  weixin
Zanui Weapp
本仓库已不再维护,请移步 https://github.com/youzan/vant-weapp
Stars: ✭ 540 (-10.74%)
Mutual labels:  weixin
3dsnakear
Well known game Snake written in Swift using ARKit.
Stars: ✭ 453 (-25.12%)
Mutual labels:  snake
Wechat sender
随时随地发送消息到微信
Stars: ✭ 474 (-21.65%)
Mutual labels:  weixin
Apfree wifidog
A hight performance and lightweight captive portal solution for HTTP(s)
Stars: ✭ 519 (-14.21%)
Mutual labels:  weixin
Wx Manage
🔥微信公众号管理系统,包含公众号菜单管理🗄、自动回复🗨、素材管理📂、模板消息☘、粉丝管理🤹‍♂️等功能,前后端都开源免费🛩
Stars: ✭ 413 (-31.74%)
Mutual labels:  weixin
Android Snake Menu
imitate Tumblr's menu, dragging animations look like a snake
Stars: ✭ 584 (-3.47%)
Mutual labels:  snake
Vim Chat
💜 Chatting plugin for neovim and vim8
Stars: ✭ 475 (-21.49%)
Mutual labels:  weixin
Wecron
✔️ 微信上的定时提醒 - Cron on WeChat
Stars: ✭ 537 (-11.24%)
Mutual labels:  weixin
Wechat Bot
带二次开发接口的PC微信聊天机器人
Stars: ✭ 458 (-24.3%)
Mutual labels:  weixin
Weindex
微信相关资源汇总索引
Stars: ✭ 466 (-22.98%)
Mutual labels:  weixin
Sns auth
通用第三方登录SDK,支持微信,微信扫码,QQ,微博登录,支付宝登录,Facebook,Line,Twitter,Google
Stars: ✭ 520 (-14.05%)
Mutual labels:  weixin
Wxpay Sdk
最新最全微信支付集成SDK,一行代码调用微信支付,包含基础支付功能(网页授权、各种签名、统一下单、退款、对账单、用户信息获取)、验收用例指引(沙箱支付、支付验收、免充值产品开通)、商户平台(现金红包、企业付款到用户、代金券或立减优惠)、公众平台(微信卡券、社交立减金活动)、小程序(生成永久二维码、发送模版消息)等等更多丰富接口注释和例子。
Stars: ✭ 443 (-26.78%)
Mutual labels:  weixin
Echarts For Weixin
Apache ECharts (incubating) 的微信小程序版本
Stars: ✭ 5,479 (+805.62%)
Mutual labels:  weixin
Wecheat
开箱即用的微信公众平台API模拟服务器,帮助你开发与调试微信公众平台应用
Stars: ✭ 440 (-27.27%)
Mutual labels:  weixin
Wux Weapp
🐶 一套组件化、可复用、易扩展的微信小程序 UI 组件库
Stars: ✭ 4,706 (+677.85%)
Mutual labels:  weixin
Ocbarrage
iOS 弹幕库 OCBarrage, 同时渲染5000条弹幕也不卡, 轻量, 可拓展, 高度自定义动画, 超高性能, 简单易上手; A barrage render-engine with high performance for iOS. At the same time, rendering 5000 barrages is also very smooth, lightweight, scalable, highly custom animation, ultra high performance, simple and easy to use!
Stars: ✭ 589 (-2.64%)
Mutual labels:  weixin
Wechat Jssdk
🐧WeChat JS-SDK integration with NodeJS
Stars: ✭ 571 (-5.62%)
Mutual labels:  weixin
Snake
🚀thinkphp5.1 + layui 实现的带rbac的基础管理后台,方便快速开发法使用
Stars: ✭ 526 (-13.06%)
Mutual labels:  snake

Snake

温馨提示:Snake已经完成AndroidX适配,请放心使用!

旧版本文档

最新版本

模块 snake-androidx snake-compiler-androidx
最新版本 Download Download

特性介绍

  • 同时支持Activity,Fragment
  • 使用简单,一行代码接入,无侵入性
  • 配置灵活,可以适配各种复杂场景
  • 适配SDK Version >= 14以上所有机型,无副作用

Demo下载体验

扫描图中二维码下载

扫描上方二维码 或 直接点这里下载

使用方法

1)添加依赖

dependencies {
    // x.x.x代表上方表格中对应模块最新版本
    implementation 'com.youngfeng.android:snake-androidx:x.x.x'
    annotationProcessor 'com.youngfeng.android:snake-compiler-androidx:x.x.x'
}

注:如果使用Kotlin,请将annotationProcessor修改为kapt

2)在Application中对初始化Snake

public class SnakeApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        
        // 对Snake进行初始化
        Snake.init(this);
    }
}

Activity集成步骤

在需要开启滑动返回的Activity类上方添加注解@EnableDragToClose即可。

@EnableDragToClose()
public class FirstActivity extends Activity

Fragment集成步骤

在Fragment中使用Snake实现滑动关闭比Activity更加灵活,推荐大家使用Fragment进行页面布局。目前,Snake提供了两种方式在Fragment中开启滑动关闭。

方法一:动态配置

第一步:在需要开启滑动返回的Fragment类上方添加注解@EnableDragToClose

@EnableDragToClose(
public class FirstFragment extends Fragment {

第二步:使用Snake提供的方法动态创建Fragment实例。

// 如果Fragment继承自androidx.fragment.app.Fragment, 则使用方法newProxySupport创建实例
FirstFragment fragment = Snake.newProxySupport(FirstFragment.class);

// 如果Fragment继承自android.app.Fragment, 则使用个方法newProxy创建实例
FirstFragment fragment = Snake.newProxy(FirstFragment.class);

注意:在不存在默认构造函数的情况下,你需要使用注解@PrimaryConstructor指定将要用于创建Fragment实例的构造方法。

@EnableDragToClose()
public class FirstFragment extends Fragment {
    
    @PrimaryConstructor
    public FirstFragment(int x, int y) {
        
    }
    
    ...
}

在使用了注解标记构造函数的情况下,使用Snake方法创建实例的时候需要传入构造参数,如下所示:

FirstFragment fragment = Snake.newProxySupport(FirstFragment.class, 1, 2);

方法二:使用继承方式集成

按照下面的对应关系,改变你的Fragment父类即可完成滑动关闭集成:

  • android.app.Fragment => com.youngfeng.snake.app.Fragment
  • androidx.fragment.app.Fragment => com.youngfeng.snake.androidx.app

注意

1)从0.4.0版本开始,support库将不再提供支持,如需继续使用support库版本Fragment,请使用0.4.0以下版本,Activity不受影响。

2)由于Android 9.0已经舍弃了android.app.Fragment类,Snake也将不再提供对该类支持,推荐大家使用androidx.app.Fragment代替。

3)Snake与Navigation暂时不兼容,如需使用Snake实现滑动关闭,需要自己控制Fragment页面导航。

滑动参数配置

通常情况下,完成上面的步骤,你已经可以正常使用滑动关闭功能了。可是,有些同学可能希望对滑动样式进行定制化。别担心, Snake提供了两种方式对滑动参数进行配置。

  • 全局滑动参数配置 如果你希望对所有页面应用滑动参数配置,可以使用snake.xml文件对参数进行配置,在工程的根目录下面,我提供了配置模板
<?xml version="1.0" encoding="utf-8"?>
<snake>
    <config>
        <!-- 设置为true,根Activity也能够滑动关闭,这很奇怪!不建议修改这个变量的默认值 -->
        <enable_for_root_activity>false</enable_for_root_activity>
        <!-- 设置为true,将监听当前页面所有位置往右快速滑动手势 -->
        <only_listen_to_fast_swipe>false</only_listen_to_fast_swipe>
        <!-- 快速滑动最低检测速度,不建议修改。过高会影响灵敏度,过低会导致误判 -->
        <min_velocity>2000</min_velocity>
        <!-- 设置为true,滑动时左侧边缘阴影将被隐藏, 这个变量的默认值也不建议修改 -->
        <hide_shadow_of_edge>false</hide_shadow_of_edge>
        <!-- 阴影边缘渐变色起始颜色 -->
        <shadow_start_color>#00000000</shadow_start_color>
        <!-- 阴影边缘渐变色结束颜色 -->
        <shadow_end_color>#50000000</shadow_end_color>
        <!-- 类似iPhone X, 从底部边缘快速上滑回到桌面 (实验性功能,默认关闭) -->
        <enable_swipe_up_to_home>false</enable_swipe_up_to_home>
        <!-- 是否允许页面联动,默认为true -->
        <allow_page_linkage>true</allow_page_linkage>
    </config>
</snake>

修改模板参数,复制当前xml文件,放到主工程目录的assets下面即可,名称必须依然是snake.xml,不能修改!

  • 单页面参数配置 如果你只希望对单个页面应用滑动参数配置,可以使用**@SetDragParameter**对其进行配置:
@EnableDragToClose()
@SetDragParameter(minVelocity = 2000, hideShadowOfEdge = false ...)
public class FirstActivity extends Activity

其它接口介绍

Snake.enableDragToClose():如果你希望动态开启或关闭【滑动关闭】特性,可以使用该接口

Snake.addDragListener():如果你希望在滑动过程中进行一些额外的处理,可以使用该接口监听整个滑动过程。

Snake.setCustomTouchInterceptor:如果你在使用过程中,出现了一些滑动冲突问题,你可以通过使用该接口自定义拦截器解决。 注意:大多数情况下你不需要理会该接口,如果确定是需要解决这种滑动冲突问题,可以使用该接口。

Snake.dragToCloseEnabled():如果你需要知道滑动关闭功能在当前页面是否处于开启状态,可以使用该接口。

Snake.enableSwipeToHome(): 如果希望在某个页面开启上滑退出到桌面功能,可以使用该接口

Snake.swipeUpToHomeEnabled(): 获取当前页面上滑退出到桌面功能开启状态

版本兼容问题处理

support替换为androidx实现

由于0.4.0版本已经移除了support库,如果你在Fragment中使用了Snake,请将support库替换为androidx实现。

移除SnakeAnimationController接口

0.4.0版本开始,snake-compiler将自动实现该接口,无需再自行实现该接口。

android.app.Fragment替换为androidx实现

0.4.0版本开始,将逐步放弃对系统Fragment的支持,如果你在Fragment中使用了系统实现,请替换为androidx实现。

依赖声明方式发生变化,需要增加-androidx后缀

implementation 'com.youngfeng.android:snake-androidx:x.x.x'
annotationProcessor 'com.youngfeng.android:snake-compiler-androidx:x.x.x'

最佳实践

1)为了避免出现大量重复代码,推荐大家使用继承的方式使用Snake。

2)Activity的启动是一个非常耗时的过程,为了体验效果更佳,推荐使用全Fragment设计,或者单Activity+多Fragment设计。

3)遇到问题请先查看Wiki,如果没有你想要的答案,请添加QQ交流群288177681及时反馈。

4)为了在Activity中获得最佳使用体验,建议大家在style文件中添加如下配置:

<item name="android:windowIsTranslucent">true</item>

5)android.app.Fragmentandroid.support.v4.app.Fragment都已经被Android官方舍弃,推荐大家始终使用androidx.fragment.app.Fragment作为Fragment类唯一选择。

混淆配置

# 如果已经应用该规则,无需重复配置
-keepattributes *Annotation*
-keep class **.*_SnakeProxy
-keep @com.youngfeng.snake.annotations.EnableDragToClose public class *

微信公众号

欧阳锋工作室

微信公众号也是一个高效的问题反馈平台,如需帮助请在微信公众号中给我留言,我会第一时间查看!*

QQ交流群

QQ群:288177681

如果你在使用过程中遇到了任何问题,欢迎加群交流。如果你想给作者支持,请点击上方star支持。

PS: 如果你在产品中使用了Snake, 请来信告诉我!邮件地址:[email protected],非常感谢!

License

Copyright 2018 Ouyangfeng Office

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].