Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact(Android): unify member-field naming convention in Kotlin #1999

Merged
merged 20 commits into from
Jan 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Migrate ScreenFragment
  • Loading branch information
kkafar committed Jan 2, 2024
commit 5e299ddf742b0101cd41b7c6026355488bb321b8
25 changes: 12 additions & 13 deletions android/src/main/java/com/swmansion/rnscreens/ScreenFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ open class ScreenFragment : Fragment, ScreenFragmentWrapper {
// if we call empty constructor, there is no screen to be assigned so not sure why it is suggested
@Suppress("JoinDeclarationAndAssignment")
override lateinit var screen: Screen
private val mChildScreenContainers: MutableList<ScreenContainer> = ArrayList()

override val childScreenContainers: MutableList<ScreenContainer> = ArrayList()

private var shouldUpdateOnResume = false
// if we don't set it, it will be 0.0f at the beginning so the progress will not be sent
// due to progress value being already 0.0f
private var mProgress = -1f
private var transitionProgress = -1f

// those 2 vars are needed since sometimes the events would be dispatched twice in child containers
// (should only happen if parent has `NONE` animation) and we don't need too complicated logic.
Expand Down Expand Up @@ -152,9 +154,6 @@ open class ScreenFragment : Fragment, ScreenFragmentWrapper {
return null
}

override val childScreenContainers: List<ScreenContainer>
get() = mChildScreenContainers

override fun canDispatchLifecycleEvent(event: ScreenLifecycleEvent): Boolean = when (event) {
ScreenLifecycleEvent.WillAppear -> canDispatchWillAppear
ScreenLifecycleEvent.Appear -> canDispatchAppear
Expand Down Expand Up @@ -213,7 +212,7 @@ open class ScreenFragment : Fragment, ScreenFragmentWrapper {
}

override fun dispatchLifecycleEventInChildContainers(event: ScreenLifecycleEvent) {
mChildScreenContainers.filter { it.screenCount > 0 }.forEach {
childScreenContainers.filter { it.screenCount > 0 }.forEach {
it.topScreen?.fragmentWrapper?.let { fragment -> dispatchLifecycleEvent(event, fragment) }
}
}
Expand All @@ -228,14 +227,14 @@ open class ScreenFragment : Fragment, ScreenFragmentWrapper {

override fun dispatchTransitionProgressEvent(alpha: Float, closing: Boolean) {
if (this is ScreenStackFragment) {
if (mProgress != alpha) {
mProgress = max(0.0f, min(1.0f, alpha))
if (transitionProgress != alpha) {
transitionProgress = max(0.0f, min(1.0f, alpha))
/* We want value of 0 and 1 to be always dispatched so we base coalescing key on the progress:
- progress is 0 -> key 1
- progress is 1 -> key 2
- progress is between 0 and 1 -> key 3
*/
val coalescingKey = (if (mProgress == 0.0f) 1 else if (mProgress == 1.0f) 2 else 3).toShort()
val coalescingKey = (if (transitionProgress == 0.0f) 1 else if (transitionProgress == 1.0f) 2 else 3).toShort()
val container: ScreenContainer? = screen.container
val goingForward = if (container is ScreenStack) container.goingForward else false
val screenContext = screen.context as ReactContext
Expand All @@ -244,19 +243,19 @@ open class ScreenFragment : Fragment, ScreenFragmentWrapper {
?.dispatchEvent(
ScreenTransitionProgressEvent(
UIManagerHelper.getSurfaceId(screenContext),
screen.id, mProgress, closing, goingForward, coalescingKey
screen.id, transitionProgress, closing, goingForward, coalescingKey
)
)
}
}
}

override fun addChildScreenContainer(container: ScreenContainer) {
mChildScreenContainers.add(container)
childScreenContainers.add(container)
}

override fun removeChildScreenContainer(container: ScreenContainer) {
mChildScreenContainers.remove(container)
childScreenContainers.remove(container)
}

override fun onViewAnimationStart() {
Expand Down Expand Up @@ -307,7 +306,7 @@ open class ScreenFragment : Fragment, ScreenFragmentWrapper {
?.dispatchEvent(ScreenDismissedEvent(surfaceId, screen.id))
}
}
mChildScreenContainers.clear()
childScreenContainers.clear()
}

companion object {
Expand Down