This file contains hidden or 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
| interface Network { | |
| fun load(): Maybe<String> | |
| } |
This file contains hidden or 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
| internal class KittenViewImpl(root: View) : AbstractMviView<Model, Event>(), KittenView { | |
| private val swipeRefreshLayout = root.findViewById<SwipeRefreshLayout>(R.id.swype_refresh) | |
| private val adapter = KittenAdapter() | |
| private val snackbar = Snackbar.make(root, R.string.error_loading_kittens, Snackbar.LENGTH_INDEFINITE) | |
| init { | |
| root.findViewById<RecyclerView>(R.id.recycler).adapter = adapter | |
| swipeRefreshLayout.setOnRefreshListener { | |
| dispatch(Event.RefreshTriggered) |
This file contains hidden or 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
| class MainFragment : Fragment(R.layout.main_fragment) { | |
| private lateinit var component: KittenComponent | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| component = KittenComponent() | |
| } | |
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
| super.onViewCreated(view, savedInstanceState) |
This file contains hidden or 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
| <androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:app="http://schemas.android.com/apk/res-auto" | |
| android:id="@+id/swype_refresh" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent"> | |
| <androidx.recyclerview.widget.RecyclerView | |
| android:id="@+id/recycler" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" |
This file contains hidden or 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
| struct Kittens: View { | |
| @State private var holder: ComponentHolder? | |
| @State private var proxy = KittenViewProxy() | |
| var body: some View { | |
| KittenSwiftView(proxy: proxy) | |
| .onAppear(perform: onAppear) | |
| .onDisappear(perform: onDisappear) | |
| } |
This file contains hidden or 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 class ComponentHolder { | |
| let component = KittenComponent() | |
| deinit { | |
| component.onDestroy() | |
| } | |
| } |
This file contains hidden or 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
| struct KittenSwiftView: View { | |
| @ObservedObject var proxy: KittenViewProxy | |
| var body: some View { | |
| NavigationView { | |
| content | |
| .navigationBarTitle("Kittens KMP Sample") | |
| .navigationBarItems( | |
| leading: ActivityIndicator(isAnimating: self.proxy.model?.isLoading ?? false, style: .medium), | |
| trailing: Button("Refresh") { |
This file contains hidden or 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
| struct KittenSwiftView: View { | |
| @ObservedObject var proxy: KittenViewProxy | |
| var body: some View { | |
| } | |
| private var content: some View { | |
| let model: KittenViewModel! = self.proxy.model | |
| return Group { |
This file contains hidden or 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
| struct KittenSwiftView: View { | |
| @ObservedObject var proxy: KittenViewProxy | |
| var body: some View { | |
| } | |
| } |
This file contains hidden or 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 Kittens | |
| class KittenViewProxy : AbstractMviView<KittenViewModel, KittenViewEvent>, KittenView, ObservableObject { | |
| @Published var model: KittenViewModel? | |
| override func render(model: KittenViewModel) { | |
| self.model = model | |
| } | |
| } |