package com.convenient.android.common.extension

import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import com.convenient.android.common.utils.ReflectionUtils

/**
 * @classname:
 * @author: LiuXiaoLong
 * @date: 2022/7/27
 * description:
 */
/****** 显示文件信息对话框 End ******/
fun DialogFragment.showAllowingStateLoss(fm: FragmentManager, tag: String) {
    try {
        /****** 通过反射修改父类的属性值：mDismissed = false  */
        ReflectionUtils.setFieldValue(this, "mDismissed", false)
        /****** 通过反射修改父类的属性值：mShownByMe = true  */
        ReflectionUtils.setFieldValue(this, "mShownByMe", true)
        fm.beginTransaction().add(this, tag).commitAllowingStateLoss()
        /****** 解决findFragmentByTag为NULL问题  */
        fm.executePendingTransactions()
    } catch (e: Exception) {
        e.printStackTrace()
    }
}