BFragment에서 CFragment로 이동을 하는데 처음 BFragment에 진입했을때는 잘 이동이 됩니다.(여러번 B에서 C로 왔다갔다 가능) 하지만 BFragment 이전에 (이전에 AFragment가 있다고 가정하고) AFragment로 갔다가 다시 BFragment로 돌아오면 CFragment로 이동이 되지 않습니다.. 라이브러리 자체 버그일까요??
BFragment
class BFragment : BaseFragment<FragmentBBinding>(R.layout.fragment_b) {
private val viewModel by activityViewModels<LocationViewModel>()
//뒤로가기 클릭
fun backBtn(view: View) {
view.findNavController().popBackStack()
}
override fun init() {
binding.fragment = this
observeViewModel()
}
private fun observeViewModel() {
viewModel.viewEvent.observe(requireActivity(), {
it.getContentIfNotHandled()?.let { event ->
Log.d("TAG", "Event : $event")
when (event) {
"SUCCESS" -> {
Log.d("TAG", "SUCCESS")
this@LocationFragment.findNavController().navigate(
LocationFragmentDirections.actionLocationFragmentToLocationSelectFragment(
"location"
)
)
}
"ERROR" -> shortShowToast("오류가 발생했습니다")
}
}
})
}
fun clickAddressSearchBtn(view: View) {
if (!TextUtils.isEmpty(binding.query.text.toString())) viewModel.searchAddress(
KEY,
"similar",
1,
10,
binding.query.text.toString()
) else shortShowToast("주소를 입력해 주세요")
}
}
ViewModel 코드
@HiltViewModel
class LocationViewModel @Inject constructor(
private val addressUseCase: SearchAddressUseCase,
private val dataStore: DataStoreModule
) : BaseViewModel() {
fun searchAddress(
Authorization: String,
analyze_type: String,
page: Int,
size: Int,
query: String
) {
viewModelScope.launch {
addressUseCase.execute(Authorization, analyze_type, page, size, query)
.let { response ->
try {
_searchAddressResponse.value = response
viewEvent("SUCCESS")
} catch (e: Exception) {
viewEvent("ERROR")
}
}
}
}
}