package com.adealink.weparty.commonui.fragment

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity


fun FragmentActivity.findFragmentInActivity(tag: String): Fragment? {
    return findFragmentInList(supportFragmentManager.fragments, tag)
}

private fun findFragmentInList(fragments: List<Fragment>, tag: String): Fragment? {
    for (fragment in fragments) {
        if (fragment.tag == tag) {
            return fragment
        }

        val childFragment = findFragmentInList(fragment.childFragmentManager.fragments, tag)
        if (childFragment != null) {
            return childFragment
        }
    }
    return null
}