Code Monkey home page Code Monkey logo

kotterknife's Introduction

Kotter Knife

Deprecated: This was a terrible idea because it allocates an object for every view reference. Do not use, and do not use anything like it. Use view binding instead.

Butter Knife-esque view binding for Kotlin.

public class PersonView(context: Context, attrs: AttributeSet?) : LinearLayout(context, attrs) {
  val firstName: TextView by bindView(R.id.first_name)
  val lastName: TextView by bindView(R.id.last_name)

  // Optional binding.
  val details: TextView? by bindOptionalView(R.id.details)

  // List binding.
  val nameViews: List<TextView> by bindViews(R.id.first_name, R.id.last_name)

  // List binding with optional items being omitted.
  val nameViews: List<TextView> by bindOptionalViews(R.id.first_name, R.id.middle_name, R.id.last_name)
}

These methods are available on subclasses of Activity, Dialog, ViewGroup, Fragment, the support library Fragment, and recycler view's ViewHolder.

Download

Currently not available via Maven Central.

A SNAPSHOT is available in the Sonatype snapshot repo.

compile 'com.jakewharton:kotterknife:0.1.0-SNAPSHOT'

You can also copy ButterKnife.kt into your source tree. The file depends on the 'support-v4' and 'recyclerview-v7' libraries but the dependency is easily removed by deleting a few lines.

Comments, suggestions, and pull requests are encouraged!

License

Copyright 2014 Jake Wharton

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.

kotterknife's People

Contributors

benjamin-bader avatar corbt avatar jakewharton avatar jaredsburrows avatar josegonzalez avatar mihyaeru21 avatar mrz avatar pine avatar qmihara avatar rharter avatar steindekker avatar tenkei avatar theelfismike avatar tinsuke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kotterknife's Issues

Don't update kotlin version without updating library version number

2 days ago with commit ffb62b0, the kotlin version was updated. This was also pushed to the sonatype repository, but the version wasn't changed. This forces all people who use the library to update their kotlin version as well.

Unfortunately, this kotlin version has a bug with proguard so we can't update yet.

As you might see, this effectively blocks us from publishing an app. Therefore, I suggest that updating the kotlin version should also force an update in the version number, that way, people can choose to update their kotlin version or not.

NPE on ReadOnlyProperty.getValue

Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object kotlin.properties.ReadOnlyProperty.getValue(java.lang.Object, kotlin.reflect.KProperty)' on a null object reference

I am subclassing a FrameLayout, and have this:
val backgroundImage: ImageView? by bindOptionalView(R.id.row_background)
then I am overriding the setBackground like this

  override fun setBackground(background: Drawable?) {
        if (backgroundImage != null) {
            backgroundImage?.apply { setImageDrawable(background) }
        } else {
            super.setBackground(background)
        }
    }

the problem is that this will be called before the layout has finished inflating and butterknife has had a chance to bind it, so a NPE is called, the only solution I've found is to add a boolean that gets set to true in the onFinishInflate() method and chances the above method to


    override fun onFinishInflate() {
        super.onFinishInflate()
        ButterKnife.bind(this)
        isInflated = true
    }

  override fun setBackground(background: Drawable?) {
        if (isInflated && backgroundImage != null) {
            backgroundImage?.apply { setImageDrawable(background) }
        } else {
            super.setBackground(background)
        }
    }

I am not sure if there's a better way around this

Problem with appcompat-v7:26.1.0

repositories {
    maven { url "https://oss.sonatype.org/content/repositories/snapshots"}
    mavenCentral()
}

compile 'com.jakewharton:kotterknife:0.1.0-SNAPSHOT'

Manifest merger fails with 26.1.0, chaing appcompat version to 26.0.2 solves the issue however.

DialogFragment use

Point 1
Kotterknife behaves in a way that if DialogFragment.getDialog() != null, it will use getDialog().findViewById() or if a getDialog() == null it will attempt getView().findViewById()

The FragmentManager calls getLayoutInflater before onCreateView, and in a DialogFragment onCreateDialog is called as part of getLayoutInflater, therefore there is no point at which a View will exist when a Dialog doesn't.

So I recommend perhaps removing the fallback as to not confuse developers looking at the source.

Point 2

The view created in onCreateView is not set to the dialog until onActivityCreated. Therefore if a behaviour of initialising the view state in onViewCreated is taken then a crash is guaranteed.

There doesn't seem to be a great way of knowing if Dialog.setContentView or FragmentonActivityCreated was called so perhaps this detail should be added to documentation?

--

I'll make a PR later, but wanted to see if this was agreeable or I'm misunderstanding why I was running into issues.

Butterknife / Kotterknife incompatibility

When using both butterknife 8.2.1 and kotterknife 0.1.0-SNAPSHOT, I get the following build error:

Error:Execution failed for task ':bux:transformClassesWithJarMergingForNightlyDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: butterknife/BuildConfig.class

I've examined the jars gradle downloads for both libraries and the butterknife/BuildConfig.class file is indeed present in both.

I guess changing the package of kotterknife to kotternife (I see it still uses butterknife as package) would solve this, right?

bindView doesn't work with CheckBox

This is the error given by the compiler:

Missing setValue(MyActivity.kotlin.reflect.KProperty<*>,android.widget.Checkbox) method on delegate of type kotlin.properties.ReadOnlyProperty<android.app.Activity, android.widget.Checkbox>

Error when included in project with butterknife

in an app I'm slowly moving over to kotlin in Build.gradle I add in:

 kapt 'com.jakewharton:butterknife-compiler:8.5.1'
  compile 'com.jakewharton:butterknife:8.5.1'
  compile 'com.jakewharton:kotterknife:0.1.0-SNAPSHOT'

When I Build it fails with:

Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lbutterknife/BuildConfig;
Error:com.android.dex.DexException: Multiple dex files define Lbutterknife/BuildConfig;
Error:	at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:608)
Error:	at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:563)
Error:	at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:545)
Error:	at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:167)
Error:	at com.android.dx.merge.DexMerger.merge(DexMerger.java:194)
Error:	at com.android.builder.dexing.DexArchiveMergerCallable.mergeDexes(DexArchiveMergerCallable.java:66)
Error:	at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:54)
Error:	at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:37)
Error:	at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
Error:	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
Error:	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
Error:	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
Error:	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error:Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lbutterknife/BuildConfig;

bindView does not work perfectly with fragment withing viewpager

I've viewpager with 5 fragments one of the fragment has recyclerView
private val recyclerView : RecyclerView by bindView(R.id.list)

It works find once it first appears but one I move to other fragment and return to the fragment that has list, the list does not appear and I get
recyclerview No adapter attached; skipping layout
I switch to regular view.findViewById(). the issue has been resolve.

it looks bindView does not bind to fragment's view or something

Why does't upload kotterknife to Maven Central ?

Hello, Jake.
I love Kotlin and kotterknife.

Today, I has not be able to compile my Android project because kotterknife uses Kotlin RC.

+--- com.jakewharton:kotterknife:0.1.0-SNAPSHOT
|    +--- com.android.support:support-v4:23.1.1 (*)
|    +--- com.android.support:recyclerview-v7:23.1.1
|    |    +--- com.android.support:support-annotations:23.1.1 -> 23.1.0
|    |    \--- com.android.support:support-v4:23.1.1 (*)
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.0-rc-1036 (*)

My project is used Kotlin beta 3 in production environment, so I was troubled very much.
Could you release kotterknife, and upload to Maven Central ?

Thank you.

Bind view in retained Fragment

@JakeWharton I was wondering if you tried to handle binding views in retained Fragments?

I will explain the problem to everyone else:
When you set your fragment retained calling setRetainInstance(true) view properties once created are kept in memory after fragment layout is re-created e.g. screen orientation changes. It means that after orientation change properties points to the view from the old invalid layout reference.
With java ButterKnife you have to call inject() in respective fragment method callback. In case this library injection is done automatically whenever view is used for the first time.

failed to resolve: com.jakewharton:kotterknife:0.1.0-SNAPSHOT

when I add compile 'com.jakewharton:kotterknife:0.1.0-SNAPSHOT' to my gradle file,it didn't work and show failed to resolve: com.jakewharton:kotterknife:0.1.0-SNAPSHOT message.This is my build.gredle file.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc2"

defaultConfig {
    applicationId "jien.kotlinandroid"
    minSdkVersion 16
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
sourceSets {

// main.java.srcDirs += 'src/main/kotlin'
debug.java.srcDirs += 'src/main/kotlin'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'com.jakewharton:kotterknife:0.1.0-SNAPSHOT'
compile 'com.android.support:recyclerview-v7:22.2.0'
}

buildscript {
ext.kotlin_version = '0.12.200'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
repositories {
mavenCentral()
}

Will @OnClick be added?

Annotations from Butterknife like @OnClick or @OnItemLongClick are not added in Kotterknife. Is this in the road map? Although view.setOnClickListener{...} from Kotlin is pretty clean, but it would be great if we can have the same code style like Butterknife.

NPE for abstract View-class

Imagine, we have an abstract base view-class:

`

abstract class CollectionFragment {
    protected val emptyView: View by bindView(R.id.empty_view)

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
    ... some base layout ...
    }
}

`

then we inherit, and we want to access some view:

`

class NewsFragment : CollectionFragment() {
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {

        val rootView: View? = super.onCreateView(inflater, container, savedInstanceState)

        emptyDataButton.visibility = View.GONE  // hide empty data button

        return rootView

    }
}

`

But we get NPE while accessing this 'emptyView':

Caused by: kotlin.KotlinNullPointerException
                                                                              at butterknife.ButterKnifeKt$viewFinder$5.invoke(ButterKnife.kt:73)
                                                                              at butterknife.ButterKnifeKt$viewFinder$5.invoke(ButterKnife.kt)
                                                                              at butterknife.ButterKnifeKt$required$1.invoke(ButterKnife.kt:82)
                                                                              at butterknife.ButterKnifeKt$required$1.invoke(ButterKnife.kt)
                                                                              at butterknife.Lazy.getValue(ButterKnife.kt:103)
                                                                              at CollectionFragment.getEmptyDataButton(CollectionFragment.kt:0)
                                                                              at NewsFragment.onCreateView(NewsFragment.kt:50)
                                                                              at android.support.v4.app.Fragment.performCreateView(Fragment.java:2189)

When we rollback to classic ButterKnife:

@BindView(R.id.btn_empty_data) lateinit var emptyDataButton: Button

everything is OK

Failed to resolve

Hi
I added sonatype dependency like this

repositories {
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots"
    }
}

and
compile 'com.jakewharton:kotterknife:0.1.0-SNAPSHOT'

to the app gradle.

But I still got Error:(39, 13) Failed to resolve: com.jakewharton:kotterknife:0.1.0-SNAPSHOT

Can someone help me with it?

RecyclerView Viewholder Bind using BaseViewholder pattern.

In My java class, I am using below BaseViewholder to Bind Adapter Viewholder.
How can I Bind itemview of below ViewHolder using kotterknife:

public class BaseViewHolder extends RecyclerView.ViewHolder {

    public View itemView;

    public BaseViewHolder(View itemView) {
        super(itemView);
        this.itemView = itemView;
        ButterKnife.bind(this, itemView);
    }

    public View getItemView() {
        return itemView;
    }
}

By pasting Java code in kotlin file I am getting below kotlin code:

class BaseViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

    init {
        ButterKnife.bind(this, itemView) // I have to Bind Item View here using kotterknife
    }
}

How can I achieve this?

Problem with SNAPSHOT

Hi Jake,

Yesterday you updated kotterknife. For some reason we got Unresolved reference: bindView.

We tried exclude groups for kotlin and support libs(we still using 25.4.0), but problem was still persisted. (Maybe binary compatibility or what)

Can you please try avoid of using snapshot without stable build? from "com.jakewharton:kotterknife:0.1.0-SNAPSHOT" to something like "com.jakewharton:kotterknife:0.1.1" , ... etc?

We did alternative solution for now: Uploaded to artifactory old library with different group name to work with ours builds. Thanks

Bind view in arbitrary class

It would be nice to be able to do something like this:

class Sample : KotterKnifeTarget {
    override val rootView = something
    val textView = bindView<TextView>(R.id.foo) /* finds the view from rootView */
}

The view binding extension methods would be on KotterKnifeTarget. This way we could use KotterKnife with Renderers or anywhere else.

Support ViewHolder pattern

Are there any plans to support bindView(R.id.xxx) in the non-recyclerview ViewHolder pattern?

Or do we have to extend RecyclerView.ViewHolder? Doesn't extended this create additional overhead?

[Question] Namespace for KotterKnife methods

Would be nice if KotterKnife's functions could be used like the code bellow?

val myButton: Button by KotterKnifer.bindView(R.id.myButton)

I want this because I want to know when I read my code where bindView comes from. My idea is to use an implementation like this for Kotter Knife:

public object KotterKnife {
    public fun <T : View> bindView(id: Int): ReadOnlyProperty<Any, T> = ViewBinding(id)
    public fun <T : View> bindOptionalView(id: Int): ReadOnlyProperty<Any, T?> = OptionalViewBinding(id)
    public fun <T : View> bindViews(vararg ids: Int): ReadOnlyProperty<Any, List<T>> = ViewListBinding(ids)
    public fun <T : View> bindOptionalViews(vararg ids: Int): ReadOnlyProperty<Any, List<T>> = OptionalViewListBinding(ids)

    // your other methods.
}

Any ideas about what I want to do? Please keep in mind that I don't care about users that would use this from Java, this means I don't care about constructions like:

KotterKnife.INSTANCE$.bindView(R.id.someid)

How to bind DialogFragment

I mostly use a DialogFragment to wrap an AlertDialog by overriding OnCreateDialog.

How can I bind views here?

With ButterKnife I used to use bind.(this, customView) but that obviously does not work here.

error with suport libraries.

there is en error when I use kotterknife in my project:
"All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 26.0.2, 25.4.0. Examples include com.android.support:recyclerview-v7:26.0.2 and com.android.support:animated-vector-drawable:25.4.0
My project just use 25.4.0 support libraries. If I remove kotterknife, there is no problem.

Generate less classes

Discovered that my previous change to eliminate reflection led to an abundance of generated classes. For the combination of the 6 targets and the 4 method types there were 24 classes generated where most were really duplicates.

Here is a patch that corrects that and reduces those 24 down to 6

diff --git a/src/main/kotlin/butterknife/ButterKnife.kt b/src/main/kotlin/butterknife/ButterKnife.kt
index 947b824..5611c25 100644
--- a/src/main/kotlin/butterknife/ButterKnife.kt
+++ b/src/main/kotlin/butterknife/ButterKnife.kt
@@ -9,60 +9,69 @@ import android.view.View
 import kotlin.properties.ReadOnlyProperty

 public fun <V : View> View.bindView(id: Int)
-    : ReadOnlyProperty<View, V> = required(id, ::findViewById)
+    : ReadOnlyProperty<View, V> = required(id, viewFinder)
 public fun <V : View> Activity.bindView(id: Int)
-    : ReadOnlyProperty<Activity, V> = required(id, ::findViewById)
+    : ReadOnlyProperty<Activity, V> = required(id, viewFinder)
 public fun <V : View> Dialog.bindView(id: Int)
-    : ReadOnlyProperty<Dialog, V> = required(id, ::findViewById)
+    : ReadOnlyProperty<Dialog, V> = required(id, viewFinder)
 public fun <V : View> Fragment.bindView(id: Int)
-    : ReadOnlyProperty<Fragment, V> = required(id, ::findViewById)
+    : ReadOnlyProperty<Fragment, V> = required(id, viewFinder)
 public fun <V : View> SupportFragment.bindView(id: Int)
-    : ReadOnlyProperty<SupportFragment, V> = required(id, ::findViewById)
+    : ReadOnlyProperty<SupportFragment, V> = required(id, viewFinder)
 public fun <V : View> ViewHolder.bindView(id: Int)
-    : ReadOnlyProperty<ViewHolder, V> = required(id, ::findViewById)
+    : ReadOnlyProperty<ViewHolder, V> = required(id, viewFinder)

 public fun <V : View> View.bindOptionalView(id: Int)
-    : ReadOnlyProperty<View, V?> = optional(id, ::findViewById)
+    : ReadOnlyProperty<View, V?> = optional(id, viewFinder)
 public fun <V : View> Activity.bindOptionalView(id: Int)
-    : ReadOnlyProperty<Activity, V?> = optional(id, ::findViewById)
+    : ReadOnlyProperty<Activity, V?> = optional(id, viewFinder)
 public fun <V : View> Dialog.bindOptionalView(id: Int)
-    : ReadOnlyProperty<Dialog, V?> = optional(id, ::findViewById)
+    : ReadOnlyProperty<Dialog, V?> = optional(id, viewFinder)
 public fun <V : View> Fragment.bindOptionalView(id: Int)
-    : ReadOnlyProperty<Fragment, V?> = optional(id, ::findViewById)
+    : ReadOnlyProperty<Fragment, V?> = optional(id, viewFinder)
 public fun <V : View> SupportFragment.bindOptionalView(id: Int)
-    : ReadOnlyProperty<SupportFragment, V?> = optional(id, ::findViewById)
+    : ReadOnlyProperty<SupportFragment, V?> = optional(id, viewFinder)
 public fun <V : View> ViewHolder.bindOptionalView(id: Int)
-    : ReadOnlyProperty<ViewHolder, V?> = optional(id, ::findViewById)
+    : ReadOnlyProperty<ViewHolder, V?> = optional(id, viewFinder)

 public fun <V : View> View.bindViews(vararg ids: Int)
-    : ReadOnlyProperty<View, List<V>> = required(ids, ::findViewById)
+    : ReadOnlyProperty<View, List<V>> = required(ids, viewFinder)
 public fun <V : View> Activity.bindViews(vararg ids: Int)
-    : ReadOnlyProperty<Activity, List<V>> = required(ids, ::findViewById)
+    : ReadOnlyProperty<Activity, List<V>> = required(ids, viewFinder)
 public fun <V : View> Dialog.bindViews(vararg ids: Int)
-    : ReadOnlyProperty<Dialog, List<V>> = required(ids, ::findViewById)
+    : ReadOnlyProperty<Dialog, List<V>> = required(ids, viewFinder)
 public fun <V : View> Fragment.bindViews(vararg ids: Int)
-    : ReadOnlyProperty<Fragment, List<V>> = required(ids, ::findViewById)
+    : ReadOnlyProperty<Fragment, List<V>> = required(ids, viewFinder)
 public fun <V : View> SupportFragment.bindViews(vararg ids: Int)
-    : ReadOnlyProperty<SupportFragment, List<V>> = required(ids, ::findViewById)
+    : ReadOnlyProperty<SupportFragment, List<V>> = required(ids, viewFinder)
 public fun <V : View> ViewHolder.bindViews(vararg ids: Int)
-    : ReadOnlyProperty<ViewHolder, List<V>> = required(ids, ::findViewById)
+    : ReadOnlyProperty<ViewHolder, List<V>> = required(ids, viewFinder)

 public fun <V : View> View.bindOptionalViews(vararg ids: Int)
-    : ReadOnlyProperty<View, List<V>> = optional(ids, ::findViewById)
+    : ReadOnlyProperty<View, List<V>> = optional(ids, viewFinder)
 public fun <V : View> Activity.bindOptionalViews(vararg ids: Int)
-    : ReadOnlyProperty<Activity, List<V>> = optional(ids, ::findViewById)
+    : ReadOnlyProperty<Activity, List<V>> = optional(ids, viewFinder)
 public fun <V : View> Dialog.bindOptionalViews(vararg ids: Int)
-    : ReadOnlyProperty<Dialog, List<V>> = optional(ids, ::findViewById)
+    : ReadOnlyProperty<Dialog, List<V>> = optional(ids, viewFinder)
 public fun <V : View> Fragment.bindOptionalViews(vararg ids: Int)
-    : ReadOnlyProperty<Fragment, List<V>> = optional(ids, ::findViewById)
+    : ReadOnlyProperty<Fragment, List<V>> = optional(ids, viewFinder)
 public fun <V : View> SupportFragment.bindOptionalViews(vararg ids: Int)
-    : ReadOnlyProperty<SupportFragment, List<V>> = optional(ids, ::findViewById)
+    : ReadOnlyProperty<SupportFragment, List<V>> = optional(ids, viewFinder)
 public fun <V : View> ViewHolder.bindOptionalViews(vararg ids: Int)
-    : ReadOnlyProperty<ViewHolder, List<V>> = optional(ids, ::findViewById)
+    : ReadOnlyProperty<ViewHolder, List<V>> = optional(ids, viewFinder)

-private fun Fragment.findViewById(id: Int): View? = getView().findViewById(id)
-private fun SupportFragment.findViewById(id: Int): View? = getView().findViewById(id)
-private fun ViewHolder.findViewById(id: Int): View? = itemView.findViewById(id)
+private val View.viewFinder: View.(Int) -> View?
+    get() = View::findViewById
+private val Activity.viewFinder: Activity.(Int) -> View?
+    get() = Activity::findViewById
+private val Dialog.viewFinder: Dialog.(Int) -> View?
+    get() = Dialog::findViewById
+private val Fragment.viewFinder: Fragment.(Int) -> View?
+    get() = { getView().findViewById(it) }
+private val SupportFragment.viewFinder: SupportFragment.(Int) -> View?
+    get() = { getView().findViewById(it) }
+private val ViewHolder.viewFinder: ViewHolder.(Int) -> View?
+    get() = { itemView.findViewById(it) }

 private fun viewNotFound(id:Int, desc: PropertyMetadata) =
     throw IllegalStateException("View ID $id for '${desc.name}' not found.")

Does kotterknife also require R2 for libraries?

I tried kotterknife by binding to R2 ids and it wasn't able to find them. However they worked with R ids. Are we supposed to use R instead of R2 or will that be inconsistent with other dependencies in the main app?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.