Created
March 24, 2016 11:40
-
-
Save jbaginski/0fd0729428557fd79c93 to your computer and use it in GitHub Desktop.
Kotlin recipes for Android: Fragment Tranaction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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