Skip to content

Instantly share code, notes, and snippets.

@jbaginski
Created March 24, 2016 11:40
Show Gist options
  • Save jbaginski/0fd0729428557fd79c93 to your computer and use it in GitHub Desktop.
Save jbaginski/0fd0729428557fd79c93 to your computer and use it in GitHub Desktop.
Kotlin recipes for Android: Fragment Tranaction
import android.app.Activity
import android.app.Fragment
import android.app.FragmentTransaction
inline fun Activity.fragmentTransaction(autocommit: Boolean = true, func: FragmentTransaction.() -> Unit) {
val transaction = fragmentManager.beginTransaction()
func.invoke(transaction)
if (autocommit && !transaction.isEmpty) {
transaction.commit()
}
}
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentActivity
import android.support.v4.app.FragmentTransaction
inline fun FragmentActivity.supportFragmentTransaction(autocommit: Boolean = true, func: FragmentTransaction.() -> Unit) {
val transaction = supportFragmentManager.beginTransaction()
func.invoke(transaction)
if (autocommit && !transaction.isEmpty) {
transaction.commit()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment