Skip to content

Conversation

@magiepooh
Copy link

Issue

Overview (Required)

  • ActivityのViewModelと同じライフサイクルを保持するScreenViewModelを作成
  • ScreenViewModelのライフサイクルを提供するScreenLifecycleを作成
  • ScreenLifecycleからJobを管理
  • ActionCreatorで使っていたPageScopeのLifecycleをScreenLifecycleへ置き換え

Links

Screenshot

Before After

@jmatsu-bot
Copy link
Collaborator

@jmatsu-bot
Copy link
Collaborator

Apk comparision results

Property Summary
New File Size 13948350 Bytes. (13.3 MB)
File Size Change -16733 Bytes. (-16.34 KB)
Download Size Change -14397 Bytes. (-14.06 KB)
New Method Reference Count 155251
Method Reference Count Change -219
New Number of dex file(s) 4
Number of dex file(s) Change 0

Generated by 🚫 Danger

@@ -1,22 +1,23 @@
package io.github.droidkaigi.confsched2019.announcement.ui.actioncreator

import androidx.lifecycle.Lifecycle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 Unused import

@@ -1,22 +1,23 @@
package io.github.droidkaigi.confsched2019.sponsor.ui.actioncreator

import androidx.lifecycle.Lifecycle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 Unused import


import androidx.annotation.IntDef

class ScreenLifecycle {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to make ScreenLifecycle a Lifecycle of AAC?
ScreenLifecycleをAACのライフサイクルにすることって可能ですかね?

import kotlinx.coroutines.launch
import javax.inject.Inject

class SponsorActionCreator @Inject constructor(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do not make a scope here, another SponsorActionCreator will be created when the screen rotates, is it difficult to make the scope?
画面回転時にもう一個インスタンスができてしまうんですが、スコープを付けるのって難しいですかね、、?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これは難しそうなので、とりあえずなくてもいいかもですね。。

/**
* This implementation refers to https://github.com/Kotlin/kotlinx.coroutines/pull/760
*/
fun ScreenLifecycle.createJob(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この実装の思想は「画面回転を跨いだActivity」が最長ライフサイクルである前提に立ってると思うんですが、実際には Application が最大であり、それに対応できていないこと、また Supervisor を使ってのViewModelのインスタンススコープから外れた Global な実装は取扱を間違えると memory leak しそうです。正確には、この実装が暗黙的なライフサイクルとコールバックチェーンに支えられていて、コードだけ見ても memory leak しないという自信がないです。
また Dagger の Provide 部分が非同期になると memory cache に適切なsemaphoreがなくて、パッと見 memory leak 無しに動くか怪しいです。非同期で provide することは現状視野に入れてませんが、暗黙的にその制約がつくのはあまり好ましくないというのが正直な感想です。

Twitter でちらっと見た感じの印象としては ViewModel が直接 CoroutineScope (と必要であれば Dagger2 のComponent) を管理するイメージでした。(最新の ktx alpha の方式)
Pros/Cons を見たいんですが、この方式で最新の ktx alpha と比較したときの Pros/Cons ってなんでしょうか?

Copy link
Contributor

@jmatsu jmatsu Jan 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ActivityのViewModelのライフサイクルを用いてCoroutineのJobを管理する

僕個人として、この考え自体には凄い賛成です。特にこのアプリはこの考えの恩恵をかなり受けられそうです。

Copy link
Member

@takahirom takahirom Jan 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これの方式との比較が気になるという感じですかね?確かにAACのライフサイクル化よりそちらを先に考えたほうがいいかもですねー
https://qiita.com/kafumi/items/8a8764679df8646b764a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants