-
Notifications
You must be signed in to change notification settings - Fork 14
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
Refactor Kotlin code to improve error handling #317
Conversation
Refactor json serialization to use null operators rather than operating on null values. No behaviour is changed. PRN-74
android/src/main/java/com/bitmovin/player/reactnative/BitmovinBaseModule.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/BitmovinBaseModule.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/BufferModule.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/BufferModule.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/BufferModule.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/SourceModule.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure Hide whitespace
is ticked to review this file.
/** | ||
* Converts an arbitrary `json` to `PlayerConfig`. | ||
* @param json JS object representing the `PlayerConfig`. | ||
* @return The generated `PlayerConfig` if successful, `null` otherwise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @param
and @return
documentation was only describing the type and name of the parameter, which is against our style guide. They have thus been removed.
android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice improvements!
I think we need some more work on the uiManager
/Promise
thing, but even that is already a good starting point!
android/src/main/java/com/bitmovin/player/reactnative/BufferModule.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/SourceModule.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/extensions/ReadableMapExtension.kt
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/extensions/CustomData.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/BitmovinBaseModule.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat that you found a solution for the Promises. This makes future review and coding a lot easier 👍
As discussed, there are still some errors, but apparently the fault is on the Arguments.fromList
.
Also, I am not sure if the nullability
is right on all the promises. I think we have to align with the type that is defined in the TS API.
android/src/main/java/com/bitmovin/player/reactnative/BitmovinBaseModule.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/PlayerModule.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/PlayerModule.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/PlayerModule.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/PlayerAnalyticsModule.kt
Outdated
Show resolved
Hide resolved
src/components/PlayerView/index.tsx
Outdated
@@ -49,7 +50,7 @@ export function PlayerView({ | |||
fullscreenHandler, | |||
customMessageHandler, | |||
isFullscreenRequested = false, | |||
scalingMode, | |||
scalingMode = ScalingMode.Fit, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alternative is to default in the Kotlin code on null.
Chose to default in the TS code aligned with isFullscreenRequest
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this could change the behaviour a bit, E.g. on iOS we don't call anything on the playerView if nothing is set:
switch scalingMode {
case "Zoom":
playerView.scalingMode = .zoom
case "Stretch":
playerView.scalingMode = .stretch
case "Fit":
playerView.scalingMode = .fit
default:
break
}
I think I would prefer not to change this, at last within this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think ignoring the command on the native side if it's invalid is the right approach (and it goes against the PR goal of reporting invalid states).
The alternative is to avoid sending the command if no scaling mode is requested: d77c955
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed - since using a default value makes a call on playerView that didn't happen before, emitting an additional event (ScalingModeChangedEvent (_DefaultScalingModeService.swift:38)) let's use the alternative approach 🙂
We can improve on this in a follow up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome improvements 💪
I noticed some things that I think we should address, but looking very good already!
android/src/main/java/com/bitmovin/player/reactnative/BitmovinBaseModule.kt
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewManager.kt
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewManager.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewManager.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewManager.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewManager.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewManager.kt
Show resolved
Hide resolved
src/components/PlayerView/index.tsx
Outdated
@@ -49,7 +50,7 @@ export function PlayerView({ | |||
fullscreenHandler, | |||
customMessageHandler, | |||
isFullscreenRequested = false, | |||
scalingMode, | |||
scalingMode = ScalingMode.Fit, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this could change the behaviour a bit, E.g. on iOS we don't call anything on the playerView if nothing is set:
switch scalingMode {
case "Zoom":
playerView.scalingMode = .zoom
case "Stretch":
playerView.scalingMode = .stretch
case "Fit":
playerView.scalingMode = .fit
default:
break
}
I think I would prefer not to change this, at last within this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing to add to @zigavehovec s comments.
After those topics are resolved this is fine to be merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Let's get this merged 💪
Problem (PRN-74 PRN-92)
The codebase had many issues:
Changes
Simplify the code and improve error visibility by:
@ReactNative
'spromise.reject
instead of ignoring them or logging them.?.
rather than operating on null values.toJson
extension function to easily chain?.
operationsJson.toXXX
extension function to easily chain?.
operationsXXXModule
variant that throws an exception if the module are not loaded, which should never happen@ReactNative
methods in a catch to report any exception instead of crashing the app@ReactCommand
promisses are guarantied to be resolved or rejected📚 Other PRs for this issue
Checklist
CHANGELOG
entry if applicable