{"id":3464,"url":"https://github.com/square/flow","last_synced_at":"2025-02-23T08:32:15.556Z","repository":{"id":10585748,"uuid":"12796207","full_name":"square/flow","owner":"square","description":"Name UI states, navigate between them, remember where you've been.","archived":true,"fork":false,"pushed_at":"2023-03-19T08:26:29.000Z","size":974,"stargazers_count":2785,"open_issues_count":36,"forks_count":238,"subscribers_count":115,"default_branch":"master","last_synced_at":"2025-02-23T05:07:58.244Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/square.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","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":"2013-09-12T22:20:16.000Z","updated_at":"2025-02-07T12:32:40.000Z","dependencies_parsed_at":"2024-01-02T21:20:23.953Z","dependency_job_id":"fc4438e3-0a84-4e61-96ea-3c6cedae5a4a","html_url":"https://github.com/square/flow","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/square%2Fflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/square","download_url":"https://codeload.github.com/square/flow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240292342,"owners_count":19778302,"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-01-05T20:16:42.257Z","updated_at":"2025-02-23T08:32:14.770Z","avatar_url":"https://github.com/square.png","language":"Java","readme":"# Deprecated\n\nFlow had a good run and served us well, but new use is strongly discouraged. The app suite at Square that drove its creation is in the process of replacing Flow with [Square Workflow](https://square.github.io/workflow/).\n\n# Flow\n\n_\"Name-giving will be the foundation of our science.\"_ \u0026mdash; Linnaeus\n\n_\"The winds and waves are always on the side of the ablest navigators.\"_ \u0026mdash; Gibbon\n\n_\"Memory is the treasury and guardian of all things._\" \u0026mdash; Cicero\n\n**Flow gives names to your Activity's UI states, navigates between them, and remembers where it's been.**\n\n## Features\n\nNavigate between UI states. Support the back button easily without confusing your users with surprising results.\n\nRemember the UI state, and its history, as you navigate and across configuration changes and process death.\n\nManage resources with set-up/tear-down hooks invoked for each UI state. UI states can easily share resources, and they'll be disposed when no longer needed.\n\nManage all types of UIs-- complex master-detail views, multiple layers, and window-based dialogs are all simple to manage.\n\n\n## Using Flow\n\nGradle:\n\n```groovy\ncompile 'com.squareup.flow:flow:1.0.0-alpha3'\n```\n\nInstall Flow into your Activity:\n\n```java\npublic class MainActivity {\n  @Override protected void attachBaseContext(Context baseContext) {\n    baseContext = Flow.configure(baseContext, this).install();\n    super.attachBaseContext(baseContext);\n  }\n}\n```\n\nBy default, Flow will take over your Activity's content view. When you start your Activity, you should see a \"Hello world\" screen. Of course you'll want to change this-- that's covered under [Controlling UI](#controlling-ui) below.\n\n### Defining UI states with key objects\n\nYour Activity's UI states are represented in Flow by Objects, which Flow refers to as \"keys\". Keys are typically [value objects][valueobject] with just enough information to identify a discrete UI state.\n\nFlow relies on a key's [equals][equals] and [hashCode][hashcode] methods for its identity. Keys should be immutable-- that is, their `equals` and `hashCode` methods should always behave the same.\n\nTo give an idea of what keys might look like, here are some examples:\n\n```java\npublic enum TabKey {\n  TIMELINE,\n  NOTIFICATIONS,\n  PROFILE\n}\n\npublic final class HomeKey extends flow.ClassKey {\n}\n\npublic final class ArticleKey {\n  public final String articleId;\n\n  public ArticleKey(String articleId) {\n    this.articleId = articleId;\n  }\n\n  public boolean equals(Object o) {\n    return o instanceof ArticleKey\n        \u0026\u0026 articleId.equals(((ArticleKey) o).articleId);\n  }\n  \n  public int hashCode() {\n    return articleId.hashCode();\n  }\n}\n```\n\nSee the [Sample Projects](#sample-projects) below for more example keys.\n\n\n### Navigation and History\nFlow offers simple commands for navigating within your app.\n\n`Flow#goBack()` -- Goes back to the previous [key][keys]. Think \"back button\".\n\n`Flow#set(key)` -- Goes to the requested key. Goes back or forward depending on whether the key is already in the History.\n\nFlow also lets you rewrite history safely and easily.\n\n`Flow#setHistory(history, direction)` -- Change history to whatever you want.\n\nSee the [Flow][Flow.java] class for other convenient operators.\n\nAs you navigate the app, Flow keeps track of where you've been. And Flow makes it easy to save view state (and any other state you wish) so that when your users go back to a place they've been before, it's just as they left it.\n\n### Controlling UI\nNavigation only counts if it changes UI state. Because every app has different needs, Flow lets you plug in [your own logic][Dispatcher.java] for responding to navigation and updating your UI.\n\nSee the Basic Sample, Tree Sample, and MultiKey Sample [below](#sample-projects) for examples.\n\n### Managing resources\nYour app requires different resources when it's in different states; sometimes those resources are shared between states. Flow [makes it easy][ServicesFactory.java] to associate resources with keys so they're set up when needed and torn down (only) when they're not anymore.\n\nSee the Tree Sample for an [example][FlowServices.java].\n\n### Surviving configuration changes and process death\nAndroid is a hostile environment. One of its greatest challenges is that your Activity or even your process can be destroyed and recreated under a variety of circumstances. Flow makes it easy to weather the storm, by automatically remembering your app's state and its history. \n\nYou [supply the serialization][KeyParceler.java] for your keys, and Flow does the rest. Flow  automatically saves and restores your History (including any state you've saved), taking care of all of the Android lifecycle events so you don't have to worry about them.\n\n## Sample projects\n\n* [Hello World](flow-sample-helloworld) - A starting point for integration.\n* [Basic Sample](flow-sample-basic) - Fully configured Flow.\n* [Tree Sample](flow-sample-tree) - Uses TreeKeys to define scopes and share state.\n* [MultiKey Sample](flow-sample-multikey) - Uses MultiKeys to represent screens with dialogs as discrete states.\n\n## License\n\n    Copyright 2013 Square, Inc.\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n[Dispatcher.java]: flow/src/main/java/flow/Dispatcher.java\n[equals]: http://developer.android.com/reference/java/lang/Object.html#equals(java.lang.Object)\n[Flow.java]: flow/src/main/java/flow/Flow.java\n[FlowServices.java]: flow-sample-tree/src/main/java/flow/sample/tree/FlowServices.java\n[hashcode]: http://developer.android.com/reference/java/lang/Object.html#hashCode()\n[KeyParceler.java]: https://github.com/square/flow/blob/master/flow/src/main/java/flow/KeyParceler.java\n[keys]: #defining-ui-states-with-key-objects\n[ServicesFactory.java]: flow/src/main/java/flow/ServicesFactory.java\n[valueobject]: https://en.wikipedia.org/wiki/Value_object\n","funding_links":[],"categories":["Java","Libraries","其他","库"],"sub_categories":["GUI","[](https://github.com/JStumpp/awesome-android/blob/master/readme.md#gui)GUI"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquare%2Fflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsquare%2Fflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquare%2Fflow/lists"}