File tree Expand file tree Collapse file tree 1 file changed +21
-16
lines changed
formview/src/main/java/com/seed/widgets/formview Expand file tree Collapse file tree 1 file changed +21
-16
lines changed Original file line number Diff line number Diff line change @@ -68,24 +68,29 @@ class FormView @JvmOverloads constructor(
6868 }
6969
7070 private fun attachCallbacks (): FormCallbacks ? {
71- if (navHostFragmentId != 0 ) {
72- val activity = context as AppCompatActivity
73- val navHostFragment =
74- activity.supportFragmentManager.findFragmentById(navHostFragmentId)
75- if (navHostFragment != null ) {
76- return when (navHostFragment) {
77- is NavHostFragment -> navHostFragment.childFragmentManager.primaryNavigationFragment
78- else -> navHostFragment
79- } as FormCallbacks
80- } else {
81- throw IllegalStateException (" Nav Host Fragment was not found. Are you sure you are providing the correct id?" )
82- }
83- }
84- return when (context) {
85- is AppCompatActivity -> (context as AppCompatActivity ) as FormCallbacks
86- is ContextThemeWrapper -> (((context as ContextThemeWrapper ).baseContext) as AppCompatActivity ) as FormCallbacks
71+ val ctx= when (context) {
72+ is AppCompatActivity -> (context as AppCompatActivity )
73+ is ContextThemeWrapper -> (((context as ContextThemeWrapper ).baseContext) as AppCompatActivity )
8774 else -> null
8875 }
76+ return ctx?.let {
77+ if (navHostFragmentId != 0 ) {
78+ val fragment =
79+ it.supportFragmentManager.findFragmentById(navHostFragmentId)
80+ if (fragment != null ) {
81+ return when (fragment) {
82+ is NavHostFragment -> fragment.childFragmentManager.primaryNavigationFragment
83+ else -> fragment
84+ } as FormCallbacks
85+ } else {
86+ throw IllegalStateException (" Nav Host Fragment was not found. Are you sure you are providing the correct id?" )
87+ }
88+ }
89+ it as FormCallbacks
90+ }
91+
92+
93+
8994 }
9095
9196
You can’t perform that action at this time.
0 commit comments