All Projects → KunMinX → Strict-DataBinding

KunMinX / Strict-DataBinding

Licence: other
善用 DataBinding 彻底解决 “View 实例的 Null 安全一致性问题”

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Strict-DataBinding

Jetpack Mvvm Best Practice
是 难得一见 的 Jetpack MVVM 最佳实践!在 以简驭繁 的代码中,对 视图控制器 乃至 标准化开发模式 形成正确、深入的理解!
Stars: ✭ 6,950 (+8173.81%)
Mutual labels:  jetpack, databinding, databinding-android
arkitekt
Arkitekt is a set of architectural tools based on Android Architecture Components, which gives you a solid base to implement the concise, testable and solid application.
Stars: ✭ 114 (+35.71%)
Mutual labels:  jetpack, databinding, jetpack-compose
Delish
Delish, a Food Recipes App in Jetpack Compose and Hilt based on modern Android tech-stacks and MVI clean architecture.
Stars: ✭ 356 (+323.81%)
Mutual labels:  jetpack, jetpack-compose
JetComposer
Collection of UIs and Animations built with Jetpack Compose for Android
Stars: ✭ 294 (+250%)
Mutual labels:  jetpack, jetpack-compose
Scout
Scout is a kotlin multiplatform application that allows users to search and save games to lists to be browsed later.
Stars: ✭ 28 (-66.67%)
Mutual labels:  jetpack, jetpack-compose
catchflicks
🎬 Kitchen sink project for learning android concepts 🎬
Stars: ✭ 12 (-85.71%)
Mutual labels:  jetpack, databinding
CloudBook
👨🏻‍💻 An ordinary person’s technical cloud notes, share the world and record life.
Stars: ✭ 38 (-54.76%)
Mutual labels:  jetpack, jetpack-compose
compose-charts
Simple Jetpack Compose Charts for multi-platform. Including Android, Web, Desktop.
Stars: ✭ 30 (-64.29%)
Mutual labels:  jetpack, jetpack-compose
WanAndroidJetpack
🔥 WanAndroid 客户端,Kotlin + MVVM + Jetpack + Retrofit + Glide。基于 MVVM 架构,用 Jetpack 实现,网络采用 Kotlin 的协程和 Retrofit 配合使用!精美的 UI,便捷突出的功能实现,欢迎下载体验!
Stars: ✭ 124 (+47.62%)
Mutual labels:  jetpack, databinding
android-developer-roadmap
🗺 The 2022 Android Developer Roadmap suggests learning paths to understanding Android development.
Stars: ✭ 5,533 (+6486.9%)
Mutual labels:  jetpack, jetpack-compose
Jetpack-compose-sample
Forget about bunch of XML files for maintaining UIs. Jetpack Compose is Android’s modern toolkit for building native UI. Here is a small example to get started.
Stars: ✭ 29 (-65.48%)
Mutual labels:  jetpack, jetpack-compose
Compose-Settings
Android #JetpackCompose Settings library
Stars: ✭ 188 (+123.81%)
Mutual labels:  jetpack, jetpack-compose
TpHulk
androidx,mvp,mvvm,jetpack
Stars: ✭ 19 (-77.38%)
Mutual labels:  jetpack, databinding
Compose-BreakingBad
🧪 ☠︎ Jetpack Compose - Breaking Bad ☢︎
Stars: ✭ 26 (-69.05%)
Mutual labels:  jetpack, jetpack-compose
samples
Jetpack Compose based project, used to stress-testing compose features / integrations and explore non-trivial functionality
Stars: ✭ 21 (-75%)
Mutual labels:  jetpack, jetpack-compose
butterfly
🦋 Butterfly helps you to build adaptive and responsive UIs for Android with Jetpack WindowManager.
Stars: ✭ 169 (+101.19%)
Mutual labels:  jetpack, jetpack-compose
Coffeegram
Android app using Jetpack Compose together with StateFlow and MVI
Stars: ✭ 155 (+84.52%)
Mutual labels:  jetpack, jetpack-compose
MovieBox
TMDb + Kotlin + Coroutines + Retrofit2 + Moshi + Clean Architecture + Koin 2 + Glide
Stars: ✭ 46 (-45.24%)
Mutual labels:  jetpack, jetpack-compose
bitcoin-market-android
Bitcoin Market app shows you the current Bitcoin market price and price chart of different time intervals 💰
Stars: ✭ 284 (+238.1%)
Mutual labels:  jetpack, jetpack-compose
modern-android
Modern Android Project Skeleton
Stars: ✭ 17 (-79.76%)
Mutual labels:  jetpack, databinding

 

DataBinding 严格模式

《Jetpack MVVM 精讲》所述,DataBinding 本质是 解决 View 实例 Null 安全一致性问题

然与函数式编程思想 "声明式 UI" 框架 Jetpack Compose 区别在于,DataBinding 并非通过 “纯函数” 方式隔绝手写代码对 “View 实例” 接触,而是 “自动化代码生成” 方式为 View 实例做 ”判空处理“,

这也就带来一问题 —— 开发者可在代码中通过 mBinding 实例调用 View 实例 —— 如此等于舍本逐末、前功尽弃。

故基于该理解,“DataBinding 严格模式” 应运而生,通过屏蔽 mBinding 使 View 实例 Null 安全一致性问题 被彻底解决,安全性与 Jetpack Compose 持平。

public class EditorFragment extends BaseFragment {
  private EditorStates mState;

  @Override
  protected DataBindingConfig getDataBindingConfig() {
    return new DataBindingConfig(R.layout.fragment_editor, BR.vm, mState)
            .addBindingParam(BR.click, new ClickProxy());
  }
  
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    ...
    mMomentRequest.getResult().observe(getViewLifecycleOwner(), result -> {
      mState.showEditorBar.set(result.editBarVisible);
    });
  }

  public static class EditorStates extends ViewModel {
    public final State<Boolean> showEditorBar = new State<>(true);
  }
}

 

Maven 依赖

鉴于 Jcenter 关闭,我们已将仓库迁移至 Maven Central,请自行于根目录 build.gradle 添加 mavenCentral()

//核心:DataBinding 严格模式基础框架
implementation 'com.kunminx.arch:strict-databinding:5.6.0'

//可选:去防抖 State
implementation 'com.kunminx.arch:binding-state:5.6.0'
//可选:常用 RecyclerView Binding 接口整理
implementation 'com.kunminx.arch:binding-recyclerview:5.6.0'

 

温馨提示:

使用 “DataBinding 严格模式” 后,“属性动画” 等 “对 View 实例强依赖” 场景,可借助 “Motion 动画” 等新式框架代替(确定 Motion 动画学习成本不足属性动画 20%,且效果好、收益高,具体视频教程可见我们在《MotionChallenge》分享)。

如对 Jetpack Compose 基于函数式编程思想 “解决 View 实例 Null 安全一致性问题” 理论基础感兴趣,详见《一通百通 “声明式 UI” 扫盲干货》,此处不做累述。

 

谁在使用

根据小伙伴们私下反馈和调查问卷,我们了解到

包括 “腾讯音乐、BMW、TCL” 在内的诸多知名厂商的软件,都参考过我们开源的 Jetpack MVVM Scaffold 架构模式,及正在使用我们维护的 UnPeek-LiveData 等框架。

“问卷调查” 我们长期保持对外开放,如有意可自行登记,以便吸引更多小伙伴 参与到对这些架构组件的使用和反馈,集众人之所长,让架构组件得以不断演化和升级。

https://wj.qq.com/s2/8362688/124a/

集团 / 公司 产品
左医科技 诊室听译机器人

 

版权声明

Copyright © 2019-present KunMinX

ReadMe 中提到的对 “DataBinding 用于规避 View 实例 Null 安全一致性问题” 的理解 等多处 对特定现象及其本质的概括,均属于本人独立原创的成果,本人对此享有最终解释权。

任何个人或组织在转载全文,或引用本文中上述提到的 描述、举例、图例或本质概括 时,须注明原作者和出处。未经授权不得用于洗稿、广告包装等商业用途。

 

Copyright 2019-present KunMinX

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].