Hi,

The way I understand tweaks is that they are mutable effects to 
> layouts/views.
>

That’s correct, although I would rather say “mutating effects”, as tweaks 
themselves are immutable.
 

> In this case, is a ListAdapterTweak also a method to modify the display of 
> the ListAdapeter? If so, where can I see what it actually does and how can 
> I compose them?
>

listAdapterTweak returns a Tweak[AbsListView], which you can apply to any 
AbsListView:

// create a tweak
val tweak = userListable.listAdapterTweak(User("Terry"), User("Graham"))
// myListView is a ListView slot
var myListView = slot[ListView]

// wire myListView to something...

runUi {
  // apply the tweak
  myListView <~ tweak
}

If you just want the adapter, there is also a listAdapter method, which 
returns it:

val adapter = userListable.listAdapter(User("Terry"), User("Graham"))
runUi {
  myListView <~ macroid.contrib.ListTweaks.adapter(adapter)
}

The second example is actually how listAdapterTweak is implemented 
internally 
:) 
https://github.com/macroid/macroid-viewable/blob/master/src/main/scala/macroid/viewable/Listable.scala#L168

Hope this helps,
Nick


> On Thursday, July 31, 2014 6:41:36 PM UTC-4, Nick Stanchenko wrote:
>>
>> Hi,
>>
>> Here’s a new library I wrote under the *Macroid* umbrella project: 
>> Macroid-Viewable: http://macroid.github.io/related/Viewable.html
>> It provides three main advantages:
>>
>>    - A clear way to declare how your data should be displayed
>>    - Boilerplate-free ListAdapters and PagerAdapters
>>    - Macroid’s trademark emphasis on composability
>>    
>> A quick example of displaying Alice and Bob in a list (with font size 
>> proportional to their age):
>>
>> import macroid._
>> import macroid.FullDsl._
>> import macroid.viewable._
>>
>> // our data type
>> case class User(name: String, age: Int)
>>
>> // defines how to view a User in a list
>> implicit def userListable(implicit ctx: ActivityContext, appCtx: 
>> AppContext) =
>>   Listable[User].tw {
>>     // the layout is a TextView
>>     w[TextView]
>>   } { user ⇒
>>     // to display a user, we tweak the layout
>>     text(user.name) + TextTweaks.size(user.age + 10)
>>   }
>>
>> // now we simply tweak the ListView
>> myListView <~ List(User("Alice", 12), User("Bob", 23)).listAdapterTweak
>>
>> Please follow the link above for more documentation and cool features.
>> Also note that I’ve just submitted the library to the jCenter repo, but 
>> until it arrives there, you might need to use the following resolver:
>>
>> resolvers += "stanch@Bintray" at "http://dl.bintray.com/stanch/maven/";
>>
>> Looking forward to hearing your feedback,
>> Nick
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"scala-on-android" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to