class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- val greetingHandler = applicationComponent.greetingHandlerFactory.create(assistedArg = "this is an assisted arg")
+ val greetingHandler = applicationComponent.greetingHandlerCreator("this is an assisted arg")
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
@HiltViewModel | |
class MyViewModel @Inject constructor( | |
private val savedStateHandle: SavedStateHandle, | |
// other dependencies | |
) : ViewModel() { | |
... | |
} |
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
generate-dependency-graph: | |
name: Generate Dependency Graph | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Setup Graphviz | |
uses: ts-graphviz/setup-graphviz@v1 |
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
// In an activity: | |
private val presenter by retain { entry -> | |
// entry exposes the viewModelScope, savedStateHandle, and a way to listen to onClear() | |
MyPresenter() | |
} | |
// Or in a composable, implicitly: | |
val presenter = retain { MyPresenter() } // this will look at LocalViewModelStoreOwner.current | |
// Or explicitly: | |
val activity = ... |
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
actual abstract class ViewModel { | |
actual val viewModelScope = MainScope() | |
protected actual open fun onCleared() {} | |
fun clear() { | |
onCleared() | |
viewModelScope.cancel() | |
} | |
} |
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
import androidx.lifecycle.ViewModel as AndroidXViewModel | |
import androidx.lifecycle.viewModelScope as androidXViewModelScope | |
actual abstract class ViewModel actual constructor() : AndroidXViewModel() { | |
actual val viewModelScope: CoroutineScope = androidXViewModelScope | |
actual override fun onCleared() { | |
super.onCleared() | |
} | |
} |
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
expect abstract class ViewModel() { | |
val viewModelScope: CoroutineScope | |
protected open fun onCleared() | |
} |
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
@Qualifier annotation class SpecialGreeting1 | |
@Qualifier annotation class SpecialGreeting2 | |
@Module | |
@InstallIn(SingletonComponent::class) | |
object GreetingModule { | |
@Provides @SpecialGreeting1 | |
fun provideSpecialGreeting1(): String = "Heeeeey" | |
@Provides @SpecialGreeting2 |
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
private let greetingHandler = InjectApplicationComponent() | |
.greetingHandlerCreator("assisted arg!") |
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
// iOS source set | |
interface PlatformComponent { | |
@Provides fun IosPlatformGreeter.bind(): PlatformGreeter = this | |
} | |
// Android source set | |
interface PlatformComponent { | |
@Provides fun AndroidPlatformGreeter.bind(): PlatformGreeter = this | |
} |