-
-
Notifications
You must be signed in to change notification settings - Fork 711
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1961 from InsertKoinIO/retained_scope_id_fix
Retained scope id fix
- Loading branch information
Showing
6 changed files
with
53 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
examples/androidx-samples/src/main/java/org/koin/sample/sandbox/scope/ScopedFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.koin.sample.sandbox.scope | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.fragment.app.Fragment | ||
import org.koin.android.scope.AndroidScopeComponent | ||
import org.koin.androidx.scope.fragmentScope | ||
import org.koin.androidx.scope.getRetainedScopeOrNull | ||
import org.koin.core.scope.Scope | ||
import org.koin.sample.sandbox.R | ||
import org.koin.sample.sandbox.components.scope.Session | ||
|
||
class ScopedFragment : Fragment(R.layout.mvvm_fragment), AndroidScopeComponent { | ||
|
||
override val scope: Scope by fragmentScope() | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
checks() | ||
} | ||
|
||
private fun checks() { | ||
assert( | ||
scope.get<Session>() == requireActivity().getRetainedScopeOrNull()?.get<Session>() | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters