Skip to content

Commit

Permalink
ui actions
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyMuse committed Apr 1, 2021
1 parent 8a52d07 commit d8b5d29
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.annotation.AnimatorRes
import androidx.core.util.set
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.navigation.NavController
Expand Down Expand Up @@ -285,4 +286,14 @@ inline fun tryOrIgnore(action: () -> Unit) = try {
action()
} catch (e: Exception) {

}

fun Fragment.goToScreen(directions: NavDirections) {
uiAction { findNavController().navigateSafe(directions) }
}

inline fun Fragment.uiAction(crossinline action: () -> Unit) {
if (viewLifecycleOwner.lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) {
action()
}
}

0 comments on commit d8b5d29

Please sign in to comment.