package com.remax.visualnovel.widget.imageviewer.utils

import android.view.View
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.remax.visualnovel.widget.imageviewer.ImageViewerDialogFragment

internal object ViewModelUtils {
    inline fun <reified T : ViewModel> provideViewModel(view: View): T? {
        return (view.activity as? FragmentActivity?)
            ?.supportFragmentManager
            ?.fragments
            ?.find { it is ImageViewerDialogFragment }
            ?.let { ViewModelProvider(it).get(T::class.java) }
    }
}