Skip to content

Commit

Permalink
Support animating shared elements on pop (#6385)
Browse files Browse the repository at this point in the history
This PR introduces support to run shared element transition animations on stack pop.
  • Loading branch information
guyca authored Jul 13, 2020
1 parent b23ab25 commit 80a52a2
Show file tree
Hide file tree
Showing 32 changed files with 519 additions and 448 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ open class AnimationOptions(json: JSONObject?) {
}
}

@JvmField
var id: Text = NullText()
@JvmField
var enabled: Bool = NullBool()
@JvmField
var waitForRender: Bool = NullBool()
@JvmField var id: Text = NullText()
@JvmField var enabled: Bool = NullBool()
@JvmField var waitForRender: Bool = NullBool()
private var valueOptions = HashSet<ValueAnimationOptions>()

fun mergeWith(other: AnimationOptions) {
if (other.id.hasValue()) id = other.id
if (other.enabled.hasValue()) enabled = other.enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import org.json.JSONObject

class ElementTransitions {
var transitions = arrayListOf<ElementTransitionOptions>()
val hasValue: Boolean
get() = transitions.isNotEmpty()

companion object {
fun parse(json: JSONObject): ElementTransitions {
Expand All @@ -25,10 +23,12 @@ class ElementTransitions {
}

fun mergeWith(other: ElementTransitions) {
if (other.hasValue) transitions = other.transitions
if (other.hasValue()) transitions = other.transitions
}

fun mergeWithDefault(defaultOptions: ElementTransitions) {
if (!hasValue) transitions = defaultOptions.transitions
if (!hasValue()) transitions = defaultOptions.transitions
}

fun hasValue() = transitions.isNotEmpty()
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.reactnativenavigation.options

import org.json.JSONException
import org.json.JSONObject
import java.util.*

class SharedElements {
private var transitions: MutableList<SharedElementTransitionOptions> = ArrayList()
fun get(): List<SharedElementTransitionOptions> {
return transitions
}

fun hasValue() = transitions.isNotEmpty()

fun mergeWith(other: SharedElements) {
if (other.hasValue()) transitions = other.transitions
}

fun mergeWithDefault(defaultOptions: SharedElements) {
if (!hasValue()) transitions = defaultOptions.transitions
}

private fun add(transition: SharedElementTransitionOptions) {
transitions.add(transition)
}

companion object {
@JvmStatic
fun parse(json: JSONObject): SharedElements {
val result = SharedElements()
return try {
val sharedElements = json.getJSONArray("sharedElementTransitions")
if (sharedElements == null || sharedElements.length() == 0) return result
for (i in 0 until sharedElements.length()) {
result.add(SharedElementTransitionOptions.parse(sharedElements.getJSONObject(i)))
}
result
} catch (e: JSONException) {
result
}
}
}
}

This file was deleted.

Loading

0 comments on commit 80a52a2

Please sign in to comment.