fix: remove setNativeProps usage (#3605)

* fix: remove `setNativeProps` usage

* code review
This commit is contained in:
Krzysztof Moch
2024-03-28 11:22:04 +01:00
committed by GitHub
parent 38746ff2ba
commit 0312afc8ea
7 changed files with 118 additions and 105 deletions

View File

@@ -70,7 +70,6 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
private static final String PROP_PREVENTS_DISPLAY_SLEEP_DURING_VIDEO_PLAYBACK = "preventsDisplaySleepDuringVideoPlayback";
private static final String PROP_PROGRESS_UPDATE_INTERVAL = "progressUpdateInterval";
private static final String PROP_REPORT_BANDWIDTH = "reportBandwidth";
private static final String PROP_SEEK = "seek";
private static final String PROP_RATE = "rate";
private static final String PROP_MIN_LOAD_RETRY_COUNT = "minLoadRetryCount";
private static final String PROP_MAXIMUM_BIT_RATE = "maxBitRate";
@@ -321,11 +320,6 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
videoView.setReportBandwidth(reportBandwidth);
}
@ReactProp(name = PROP_SEEK)
public void setSeek(final ReactExoplayerView videoView, final float seek) {
videoView.seekTo(Math.round(seek * 1000f));
}
@ReactProp(name = PROP_RATE)
public void setRate(final ReactExoplayerView videoView, final float rate) {
videoView.setRateModifier(rate);

View File

@@ -1,38 +0,0 @@
package com.brentvatne.react;
import android.view.View;
import androidx.annotation.NonNull;
import com.brentvatne.exoplayer.ReactExoplayerView;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.uimanager.UIManagerModule;
public class VideoManagerModule extends ReactContextBaseJavaModule {
private static final String REACT_CLASS = "VideoManager";
public VideoManagerModule(ReactApplicationContext reactContext) {
super(reactContext);
}
@NonNull
@Override
public String getName() {
return REACT_CLASS;
}
@ReactMethod
public void setPlayerPauseState(Boolean paused, int reactTag) {
UIManagerModule uiManager = getReactApplicationContext().getNativeModule(UIManagerModule.class);
uiManager.prependUIBlock(manager -> {
View view = manager.resolveView(reactTag);
if (view instanceof ReactExoplayerView) {
ReactExoplayerView videoView = (ReactExoplayerView) view;
videoView.setPausedModifier(paused);
}
});
}
}

View File

@@ -0,0 +1,59 @@
package com.brentvatne.react
import com.brentvatne.common.toolbox.ReactBridgeUtils
import com.brentvatne.exoplayer.ReactExoplayerView
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.UiThreadUtil
import com.facebook.react.uimanager.UIManagerModule
import kotlin.math.roundToInt
class VideoManagerModule(reactContext: ReactApplicationContext?) : ReactContextBaseJavaModule(reactContext) {
override fun getName(): String {
return REACT_CLASS
}
private fun performOnPlayerView(reactTag: Int, callback: (ReactExoplayerView?) -> Unit) {
UiThreadUtil.runOnUiThread {
val view = if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
reactApplicationContext.fabricUIManager?.resolveView(
reactTag
)
} else {
val uiManager = reactApplicationContext.getNativeModule(UIManagerModule::class.java)
uiManager?.resolveView(reactTag)
}
if (view is ReactExoplayerView) {
callback(view)
} else {
callback(null)
}
}
}
@ReactMethod
fun setPlayerPauseState(paused: Boolean?, reactTag: Int) {
performOnPlayerView(reactTag) {
it?.setPausedModifier(paused!!)
}
}
@ReactMethod
fun seek(info: ReadableMap, reactTag: Int) {
if (!info.hasKey("time")) {
return
}
val time = ReactBridgeUtils.safeGetInt(info, "time")
performOnPlayerView(reactTag) {
it?.seekTo((time * 1000f).roundToInt().toLong())
}
}
companion object {
private const val REACT_CLASS = "VideoManager"
}
}