-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove
setNativeProps
usage (#3605)
* fix: remove `setNativeProps` usage * code review
- Loading branch information
1 parent
38746ff
commit 0312afc
Showing
7 changed files
with
118 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
android/src/main/java/com/brentvatne/react/VideoManagerModule.java
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
android/src/main/java/com/brentvatne/react/VideoManagerModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters