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

[New Arch] Android Fabric #3204

Open
wants to merge 61 commits into
base: master
Choose a base branch
from

Conversation

yungblud
Copy link
Contributor

@yungblud yungblud commented Aug 11, 2023

Thanks for opening a PR!
Since this is a volunteer project and is very active, anything you can do to reduce the amount of time needed to review and merge your PR is appreciated.
The following steps will help get your PR merged quickly:

Update the documentation

For now, I don't know what to be added to README.md
Let me know if you want something to add.

Update the changelog

  • implemented android fabric

Provide an example of how to test the change

cd examples/FabricExample
yarn
yarn android

OR if above command doesn't work, you can directly

  • open Android Studio.
  • Sync gradle
  • Run

If you see build failure with Android Studio, you can try open -a /Applications/Android\ Studio.app

Focus the PR on only one area

Testing multiple features takes longer than isolated changes and if there is a bug in one feature, prevents the other parts of your PR from getting merged until it gets fixed.
If you're touching multiple different areas that aren't related, break the changes up into multiple PRs.

Describe the changes

In this PR, we've implemented android fabric.
So there are lots of file changes in android directory.
We implemented Kotlin for fabric android.

Major changes

  • We divided directory structure with src/fabric and src/oldarch on android side.
  • migrated fabric events
  • added finished (boolean) parameter on seek event for detecting when seek is finished.
  • implemented typescript on javascript side.
  • implemented fabric component view on javascript side.
  • migrated JS to TS
  • implemented codegen types with typescript

Deprecated methods (because of codegen doesn't support array callback parameters, see this issue)

  • onTimedMetadata?: (e: OnTimedMetadataData) => void //Android, iOS
  • onAudioTracks?: (e: OnAudioTracksData) => void // Android
  • onTextTracks?: (e: OnTextTracksData) => void //Android
  • onVideoTracks?: (e: OnVideoTracksData) => void //Android

React Native New Architecture's codegen doesn't support array callback parameters for native methods.

// @todo: fix type. for now react native doesn't support array codegen type for native event
export type OnAudioTracksData = Readonly<{}>
// export type _OnAudioTracksData = Readonly<{
//   audioTracks: ReadonlyArray<Readonly<{
//     index?: Int32
//     title?: string
//     language?: string
//     bitrate?: Float
//     type?: string
//     selected?: boolean
//   }>>
// }>

You can see this kind of comments for above methods on src/fabric/VideoNativeComponent.tsx.

There are some meaningless file changes.

  • examples/basic/src/VideoPlayer.ios.tsx
  • ios/Video/DataStructures/DRMParams.swift
  • ios/Video/Features/RCTResourceLoaderDelegate.swift
  • ios/Video/RCTVideoManager.swift
    These files are changed because of simple lint issue. So you can skip that files.

private static final String PROP_DRM_LICENSESERVER = "licenseServer";
private static final String PROP_DRM_HEADERS = "headers";
private static final String PROP_SRC_HEADERS = "requestHeaders";
private static final String PROP_RESIZE_MODE = "resizeMode";
private static final String PROP_REPEAT = "repeat";
private static final String PROP_SELECTED_AUDIO_TRACK = "selectedAudioTrack";
private static final String PROP_SELECTED_AUDIO_TRACK_TYPE = "type";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes change the api ?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3f12e34

Please look at this commit.
It would change api as you said.
But it's necessary.

For similar case, we can find out "selectedAudioTrack".
This naming change is needed because of CodeGen with "WithDefault".
We use WithDefault type for codegen, but with it, we cannot declare same naming of WithDefault.

* @return A HashMap containing the data that was in the ReadableMap.
* @see 'Adapted from https://github.com/artemyarulin/react-native-eval/blob/master/android/src/main/java/com/evaluator/react/ConversionUtil.java'
*/
public static Map<String, String> toStringMap(@Nullable ReadableMap readableMap) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function can be extracted to a helper function !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's true.
But we're not using it anywhere in the codebase.
So if you are okay, I will remove it.
But it's okay to move that function to another directory such as "helper"

"description": "A <Video /> element for react-native",
"main": "lib/index",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is an error here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. It's correct way.
We should export "src/index.ts"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, my bad.
I didn't know that you export build files.
yep, this should be changed to "lib/index"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a813592

I've finished !

@@ -0,0 +1,322 @@
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to factorize this file with VideoNativeComponent.ts already available on master ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I've finished that task.
We won't use 'src/fabric' folder anymore.

@freeboub
Copy link
Collaborator

@yungblud thank you very much for the maintenance on this PR 🙏
If you want to extract ts change sin a separated PR it would allow to merge changes step by step !
I would appreciate if possible ...

@@ -1431,8 +1431,9 @@ public void onPlaybackParametersChanged(PlaybackParameters params) {

@Override
public void onVolumeChanged(float volume) {
eventEmitter.volumeChange(volume);
}
// todo
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tado here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think onVolumeChanged and onAdError are new APIs
So I have to implement it for Fabric.
I will let you know when it's implemented.

}
}
eventEmitter.timedMetadata(metadataArray);
// ArrayList<TimedMetadata> metadataArray = new ArrayList<>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented code here also

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I cleaned it.

@yungblud
Copy link
Contributor Author

yungblud commented Jan 2, 2024

@freeboub Hello. No problem.
So do you want more splitted PR for implementing android fabric?
I think we can start reviews from now on on this PR.

@yungblud
Copy link
Contributor Author

yungblud commented Jan 12, 2024

@freeboub
Hello, I think we should not use enum typescript types on codegen codebase (like VideoNativeComponent.ts)
Because of codegen.
스크린샷 2024-01-12 오후 2 17 56
As you can see, codegen cannot handle with typescript enum type.
So we have to switch enums to just object values.

@yungblud
Copy link
Contributor Author

@freeboub hey, I think I've almost finished your review.
So can you check about them?
Thanks.

@yungblud yungblud requested a review from freeboub January 12, 2024 07:03
@yungblud
Copy link
Contributor Author

@freeboub hey, I splitted codegen support PR on this
Let's start from that PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants