Skip to content
This repository was archived by the owner on Sep 3, 2023. It is now read-only.

Commit

Permalink
When requesting permission from Fragment, use child fragment manager. R…
Browse files Browse the repository at this point in the history
…esolves #13.
  • Loading branch information
afollestad committed May 14, 2019
1 parent 78e5ec9 commit 311cb3b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,10 @@ internal fun FragmentActivity.transact(action: FragmentTransaction.(Context) ->
}

internal fun Fragment.transact(action: FragmentTransaction.(Context) -> Unit) {
val fm = fragmentManager ?: throw IllegalStateException(
"Fragment manager unexpectedly null."
)
fm.beginTransaction()
childFragmentManager.beginTransaction()
.apply {
action(activity ?: throw IllegalStateException("Fragment's activity is null."))
commit()
}
fm.executePendingTransactions()
childFragmentManager.executePendingTransactions()
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.afollestad.assent.Permission.CALL_PHONE
import com.afollestad.assent.Permission.READ_CALENDAR
import com.afollestad.assent.Permission.WRITE_EXTERNAL_STORAGE
import com.afollestad.assent.askForPermissions
import com.afollestad.assentsample.R.layout
Expand All @@ -27,8 +28,10 @@ class ExampleChildFragment : Fragment() {
savedInstanceState: Bundle?
) {
super.onViewCreated(view, savedInstanceState)
requestPermissionButtonChild.setOnClickListener {
askForPermissions(WRITE_EXTERNAL_STORAGE, CALL_PHONE) { }
askForPermissions(CALL_PHONE) {
requestPermissionButtonChild.setOnClickListener {
askForPermissions(WRITE_EXTERNAL_STORAGE, CALL_PHONE) { }
}
}
}
}

0 comments on commit 311cb3b

Please sign in to comment.