{"id":13645000,"url":"https://github.com/YoKeyword/SwipeBackFragment","last_synced_at":"2025-04-21T11:32:26.702Z","repository":{"id":108734934,"uuid":"56775348","full_name":"YoKeyword/SwipeBackFragment","owner":"YoKeyword","description":"An Android library that can finish a Fragment\u0026Activity with swipe-back gesture.","archived":false,"fork":false,"pushed_at":"2018-11-29T03:06:01.000Z","size":2110,"stargazers_count":505,"open_issues_count":17,"forks_count":80,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-04-06T00:09:46.525Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YoKeyword.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-04-21T13:19:22.000Z","updated_at":"2025-01-07T06:03:30.000Z","dependencies_parsed_at":"2023-03-26T12:48:03.912Z","dependency_job_id":null,"html_url":"https://github.com/YoKeyword/SwipeBackFragment","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YoKeyword%2FSwipeBackFragment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YoKeyword%2FSwipeBackFragment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YoKeyword%2FSwipeBackFragment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YoKeyword%2FSwipeBackFragment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YoKeyword","download_url":"https://codeload.github.com/YoKeyword/SwipeBackFragment/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250048010,"owners_count":21366160,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:02:23.477Z","updated_at":"2025-04-21T11:32:26.659Z","avatar_url":"https://github.com/YoKeyword.png","language":"Java","readme":"# SwipeBackFragment\nAn Android library that can finish a Fragment\u0026amp;Activity with swipe-back gesture.\n\n滑动Fragment\u0026Activity边缘即可类似IOS一样，拖动返回。\n\n原理分析：[传送门](http://www.jianshu.com/p/626229ca4dc2),  如果你重度使用Fragment，不妨看看这个库[Fragmentation](https://github.com/YoKeyword/Fragmentation)\n\n# 特性\n注: 滑动返回仅支持通过add方式加载的Fragment, replace不支持\n\n1、Activity内Fragment数大于1时，滑动返回的是Fragment，否则滑动返回的是Activity\n\n2、支持左、右、左\u0026右滑动（未来可能会增加更多滑动区域）\n\n3、支持Swipe时的滑动监听\n\n4、帮你处理了Fragment重叠的情况\n\n# Demo演示\n\u003cimg src=\"gif/swipe.gif\"/\u003e\n\n# 如何使用\n1、项目下app的build.gradle中依赖：\n````gradle\n// appcompat v7包是必须的\ncompile 'me.yokeyword:swipebackfragment:0.4.0'\n````\n2、如果Activity也需要支持SwipeBack，则继承SwipeBackActivity:\n````java\npublic class SwipeBackSampleActivity extends SwipeBackActivity {}\n````\n同时该Activity的theme添加如下属性：\n````xml\n \u003citem name=\"android:windowIsTranslucent\"\u003etrue\u003c/item\u003e\n````\n\n3、如果Fragment需要支持SwipeBack，则继承SwipeBackFragment:\n````java\npublic class SwipeBackSampleFragment extends SwipeBackFragment {\n @Override\n    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {\n        View view = inflater.inflate(R.layout.xxx, container, false);\n        // 需要支持SwipeBack则这里必须调用toSwipeBackFragment(view);\n        return attachToSwipeBack(view);\n    }\n}\n````\n\n更多方法:\n````java\n  // 设置滑动方向\n  getSwipeBackLayout().setEdgeOrientation(SwipeBackLayout.EDGE_RIGHT); // EDGE_LEFT(默认),EDGE_ALL\n  // 设置侧滑触摸生效区域 MAX,MED,MIN,custom\n  setEdgeLevel(SwipeBackLayout.EdgeLevel edgeLevel)\n  // 滑动过程监听\n  getSwipeBackLayout().addSwipeListener(new SwipeBackLayout.OnSwipeListener() {\n            @Override\n            public void onDragStateChange(int state) {\n                // Drag state\n            }\n\n            @Override\n            public void onEdgeTouch(int edgeFlag) {\n                // 触摸的边缘flag\n            }\n\n            @Override\n            public void onDragScrolled(float scrollPercent) {\n                // 滑动百分比\n            }\n   });\n\n    // 对于SwipeBackActivity有下面控制SwipeBack优先级的方法:\n      /**\n        * 限制SwipeBack的条件,默认栈内Fragment数 \u003c= 1时 , 优先滑动退出Activity , 而不是Fragment\n        *\n        * 可以通过复写该方法, 自由控制优先级\n        *\n        * @return true: Activity可以滑动退出, 并且总是优先;  false: Activity不允许滑动退出\n        */\n        @Override\n        public boolean swipeBackPriority() {\n           return super.swipeBackPriority();\n           // 下面是默认实现:\n           // return getSupportFragmentManager().getBackStackEntryCount() \u003c= 1;\n        }\n````\n\n# 致谢\n[ikew0ng/SwipeBackLayout](https://github.com/ikew0ng/SwipeBackLayout)\n\n","funding_links":[],"categories":["滑动返回"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FYoKeyword%2FSwipeBackFragment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FYoKeyword%2FSwipeBackFragment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FYoKeyword%2FSwipeBackFragment/lists"}