diff options
author | George Mount <mount@google.com> | 2018-02-01 16:12:09 -0800 |
---|---|---|
committer | George Mount <mount@google.com> | 2018-02-06 13:12:27 -0800 |
commit | bbcef5a45b5f82ecb008b68fbf8c37f1a5b815e0 (patch) | |
tree | 63f4f292afba3d8264ab2ed8d9aaf97c3d7ef176 /compiler | |
parent | bb12a46d3a8dcf51d0991f6197fdd3033f01b3db (diff) | |
download | data-binding-bbcef5a45b5f82ecb008b68fbf8c37f1a5b815e0.tar.gz |
Pass LifecycleOwner to included bound layouts
Bug: 72134952
Included layouts weren't getting passed the LifecycleOwner
so data binding expressions did not listen for changes.
Test: ran against test app
Test: new test for LiveData
Test: ran all TestApp tests
Change-Id: I702c418216fedf99603e2de302648f41146054dc
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt b/compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt index 6659cd53..a3755f85 100644 --- a/compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt +++ b/compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt @@ -374,6 +374,7 @@ class LayoutBinderWriter(val layoutBinder : LayoutBinder) { nl(declareHasPendingBindings()) nl(declareSetVariable()) nl(variableSettersAndGetters()) + nl(declareSetLifecycleOwnerOverride()) nl(onFieldChange()) try { Scope.enter(Scope.GLOBAL) @@ -758,6 +759,19 @@ class LayoutBinderWriter(val layoutBinder : LayoutBinder) { } } + fun declareSetLifecycleOwnerOverride() = kcode("") { + val includes = includedBinders.filter { it.isUsed } + if (includes.isNotEmpty()) { + nl("@Override") + block("public void setLifecycleOwner(@Nullable android.arch.lifecycle.LifecycleOwner lifecycleOwner)") { + nl("super.setLifecycleOwner(lifecycleOwner);") + includes.forEach { binder -> + nl("${binder.fieldName}.setLifecycleOwner(lifecycleOwner);"); + } + } + } + } + fun onFieldChange() = kcode("") { nl("@Override") nl("protected boolean onFieldChange(int localFieldId, Object object, int fieldId) {") { |