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

Convert DefaultDevLoadingView.java->.kt #45729

Closed
wants to merge 11 commits into from
31 changes: 23 additions & 8 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,14 @@ public abstract interface class com/facebook/react/ViewManagerOnDemandReactPacka
public abstract fun getViewManagerNames (Lcom/facebook/react/bridge/ReactApplicationContext;)Ljava/util/Collection;
}

public abstract interface class com/facebook/react/animated/AnimatedNodeValueListener {
public abstract fun onValueUpdate (D)V
}

public abstract interface class com/facebook/react/animated/AnimatedNodeWithUpdateableConfig {
public abstract fun onUpdateConfig (Lcom/facebook/react/bridge/ReadableMap;)V
}

public class com/facebook/react/animated/NativeAnimatedModule : com/facebook/fbreact/specs/NativeAnimatedModuleSpec, com/facebook/react/bridge/LifecycleEventListener, com/facebook/react/bridge/UIManagerListener {
public static final field ANIMATED_MODULE_DEBUG Z
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;)V
Expand Down Expand Up @@ -2051,14 +2059,18 @@ public class com/facebook/react/devsupport/BundleDownloader$BundleInfo {
public fun toJSONString ()Ljava/lang/String;
}

public class com/facebook/react/devsupport/DefaultDevLoadingViewImplementation : com/facebook/react/devsupport/interfaces/DevLoadingViewManager {
public final class com/facebook/react/devsupport/DefaultDevLoadingViewImplementation : com/facebook/react/devsupport/interfaces/DevLoadingViewManager {
public static final field Companion Lcom/facebook/react/devsupport/DefaultDevLoadingViewImplementation$Companion;
public fun <init> (Lcom/facebook/react/devsupport/ReactInstanceDevHelper;)V
public fun hide ()V
public static fun setDevLoadingEnabled (Z)V
public fun showMessage (Ljava/lang/String;)V
public fun updateProgress (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Integer;)V
}

public final class com/facebook/react/devsupport/DefaultDevLoadingViewImplementation$Companion {
public final fun setDevLoadingEnabled (Z)V
}

public final class com/facebook/react/devsupport/DefaultDevSupportManagerFactory : com/facebook/react/devsupport/DevSupportManagerFactory {
public fun <init> ()V
public final fun create (Landroid/content/Context;Lcom/facebook/react/devsupport/ReactInstanceDevHelper;Ljava/lang/String;ZI)Lcom/facebook/react/devsupport/interfaces/DevSupportManager;
Expand Down Expand Up @@ -2712,7 +2724,7 @@ public class com/facebook/react/fabric/events/EventEmitterWrapper {
public fun dispatchUnique (Ljava/lang/String;Lcom/facebook/react/bridge/WritableMap;)V
}

public class com/facebook/react/fabric/events/FabricEventEmitter : com/facebook/react/uimanager/events/RCTModernEventEmitter {
public final class com/facebook/react/fabric/events/FabricEventEmitter : com/facebook/react/uimanager/events/RCTModernEventEmitter {
public fun <init> (Lcom/facebook/react/fabric/FabricUIManager;)V
public fun receiveEvent (IILjava/lang/String;Lcom/facebook/react/bridge/WritableMap;)V
public fun receiveEvent (IILjava/lang/String;ZILcom/facebook/react/bridge/WritableMap;I)V
Expand Down Expand Up @@ -5549,12 +5561,13 @@ public abstract interface class com/facebook/react/uimanager/events/BatchEventDi
public abstract fun onBatchEventDispatched ()V
}

public class com/facebook/react/uimanager/events/BlackHoleEventDispatcher : com/facebook/react/uimanager/events/EventDispatcher {
public final class com/facebook/react/uimanager/events/BlackHoleEventDispatcher : com/facebook/react/uimanager/events/EventDispatcher {
public static final field Companion Lcom/facebook/react/uimanager/events/BlackHoleEventDispatcher$Companion;
public fun addBatchEventDispatchedListener (Lcom/facebook/react/uimanager/events/BatchEventDispatchedListener;)V
public fun addListener (Lcom/facebook/react/uimanager/events/EventDispatcherListener;)V
public fun dispatchAllEvents ()V
public fun dispatchEvent (Lcom/facebook/react/uimanager/events/Event;)V
public static fun get ()Lcom/facebook/react/uimanager/events/EventDispatcher;
public static final fun get ()Lcom/facebook/react/uimanager/events/EventDispatcher;
public fun onCatalystInstanceDestroyed ()V
public fun registerEventEmitter (ILcom/facebook/react/uimanager/events/RCTEventEmitter;)V
public fun registerEventEmitter (ILcom/facebook/react/uimanager/events/RCTModernEventEmitter;)V
Expand All @@ -5563,11 +5576,13 @@ public class com/facebook/react/uimanager/events/BlackHoleEventDispatcher : com/
public fun unregisterEventEmitter (I)V
}

public class com/facebook/react/uimanager/events/ContentSizeChangeEvent : com/facebook/react/uimanager/events/Event {
public static final field EVENT_NAME Ljava/lang/String;
public final class com/facebook/react/uimanager/events/BlackHoleEventDispatcher$Companion {
public final fun get ()Lcom/facebook/react/uimanager/events/EventDispatcher;
}

public final class com/facebook/react/uimanager/events/ContentSizeChangeEvent : com/facebook/react/uimanager/events/Event {
public fun <init> (III)V
public fun <init> (IIII)V
protected fun getEventData ()Lcom/facebook/react/bridge/WritableMap;
public fun getEventName ()Ljava/lang/String;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.animated;
package com.facebook.react.animated

/** Interface used to listen to {@link ValueAnimatedNode} updates. */
interface AnimatedNodeValueListener {
void onValueUpdate(double value);
/** Interface used to listen to [ValueAnimatedNode] updates. */
public fun interface AnimatedNodeValueListener {
public fun onValueUpdate(value: Double)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.animated;
package com.facebook.react.animated

import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableMap

/** Indicates that AnimatedNode is able to receive native config updates. */
interface AnimatedNodeWithUpdateableConfig {
void onUpdateConfig(ReadableMap config);
public fun interface AnimatedNodeWithUpdateableConfig {
public fun onUpdateConfig(config: ReadableMap?)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.animated

import com.facebook.react.bridge.ReadableMap
import kotlin.math.abs
import kotlin.math.exp

/**
* Implementation of [AnimationDriver] providing support for decay animations. The implementation is
* copied from the JS version in `AnimatedImplementation.js`.
*/
internal class DecayAnimation(config: ReadableMap) : AnimationDriver() {
private var velocity: Double = 0.0
private var deceleration: Double = 0.0
private var startFrameTimeMillis: Long = -1
private var fromValue: Double = 0.0
private var lastValue: Double = 0.0
private var iterations: Int = 1
private var currentLoop: Int = 1

init {
resetConfig(config)
}

public override fun resetConfig(config: ReadableMap): Unit {
velocity = config.getDouble("velocity")
deceleration = config.getDouble("deceleration")
startFrameTimeMillis = -1
fromValue = 0.0
lastValue = 0.0
iterations = if (config.hasKey("iterations")) config.getInt("iterations") else 1
currentLoop = 1
mHasFinished = iterations == 0
}

public override fun runAnimationStep(frameTimeNanos: Long) {
val frameTimeMillis = frameTimeNanos / 1000000
if (startFrameTimeMillis == -1L) {
// since this is the first animation step, consider the start to be on the previous frame
startFrameTimeMillis = frameTimeMillis - 16
if (fromValue == lastValue) { // first iteration, assign mFromValue based on mAnimatedValue
fromValue = mAnimatedValue.mValue
} else { // not the first iteration, reset mAnimatedValue based on mFromValue
mAnimatedValue.mValue = fromValue
}
lastValue = mAnimatedValue.mValue
}
val value =
(fromValue +
velocity / (1 - deceleration) *
(1 - exp(-(1 - deceleration) * (frameTimeMillis - startFrameTimeMillis))))
if (abs(lastValue - value) < 0.1) {
if (iterations == -1 || currentLoop < iterations) { // looping animation, return to start
// set mStartFrameTimeMillis to -1 to reset instance variables on the next runAnimationStep
startFrameTimeMillis = -1
currentLoop++
} else { // animation has completed
mHasFinished = true
return
}
}
lastValue = value
mAnimatedValue.mValue = value
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.animated

import com.facebook.react.bridge.JSApplicationCausedNativeException
import com.facebook.react.bridge.ReadableMap
import kotlin.math.max
import kotlin.math.min

internal class DiffClampAnimatedNode(
config: ReadableMap,
private val nativeAnimatedNodesManager: NativeAnimatedNodesManager
) : ValueAnimatedNode() {
private val inputNodeTag: Int
private val minValue: Double
private val maxValue: Double
private var lastValue: Double = 0.0

init {
inputNodeTag = config.getInt("input")
minValue = config.getDouble("min")
maxValue = config.getDouble("max")
mValue = lastValue
}

override fun update() {
val value = inputNodeValue
val diff = value - lastValue
lastValue = value
mValue = min(max(mValue + diff, minValue), maxValue)
}

private val inputNodeValue: Double
get() {
val animatedNode = nativeAnimatedNodesManager.getNodeById(inputNodeTag)
if (animatedNode == null || animatedNode !is ValueAnimatedNode) {
throw JSApplicationCausedNativeException(
"Illegal node ID set as an input for Animated.DiffClamp node")
}
return animatedNode.value
}

override fun prettyPrint(): String =
"DiffClampAnimatedNode[$mTag]: InputNodeTag: $inputNodeTag min: $minValue " +
"max: $maxValue lastValue: $lastValue super: ${super.prettyPrint()}"
}
Loading
Loading