package com.zxhyis.toolss.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding

abstract class TopFragment<T : ViewBinding> : Fragment() {
//    private val result =
//        registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
//            resultAction?.invoke(it)
//            resultAction = null
//        }
//    var resultAction: ((it: ActivityResult) -> Unit)? = null
//    fun launchResult(intent: Intent, resultAction: (it: ActivityResult) -> Unit) {
//        this.resultAction = resultAction
//        result.launch(intent)
//    }


    private var _binding: T? = null

    protected val mK: T
        get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        _binding = createBinding(inflater, container)
        return mK.root
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }

    abstract fun createBinding(inflater: LayoutInflater, container: ViewGroup?): T
}