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

Fabric (New Architecture) codegen support #3487

Conversation

yungblud
Copy link
Contributor

Update the documentation

If you've added new functionality, update the README.md with an entry for your prop or event.
The entry should be inserted in alphabetical order.

Update the changelog

I've completed fully functioning codegen generate.

Provide an example of how to test the change

I've added yarn codgen script to package.json, so you guys can test codegen by run that script.

Focus the PR on only one area

  • Focused on codegen types.

Describe the changes

  • moved src/VideoNativeComponent.ts to src/specs/VideoNativeComponent.ts
  • modified react codegen types for running codegen successfully

@yungblud
Copy link
Contributor Author

@KrzysztofMoch Let me know if I have to fix or implement other things in this PR.
I've only focused for implementing codegen support in this PR.
Cheers.

@yungblud
Copy link
Contributor Author

@KrzysztofMoch One more issue I found is "headers" on src.
In codegen types, we cannot support Record<string, string> type.
So we have to convert them as Array which has {key: string, value: string}.

I did it like this.
https://github.com/react-native-video/react-native-video/pull/3487/files#diff-70773b05560f0897b24b4baa0ed114158fd50e075c0c76de43cc30b90043eb80R16

and created one more util function to fix type issue.
https://github.com/react-native-video/react-native-video/pull/3487/files#diff-39b2554fd18da165b59a6351b1aafff3714e2a80c1435f2de9706355b4d32351R9

finally, I implemented that util function to these.
https://github.com/react-native-video/react-native-video/pull/3487/files#diff-272334bc4a560000e8736860b4e6980d3f865b9abea3baee3bfee41ab1894bd6R149
https://github.com/react-native-video/react-native-video/pull/3487/files#diff-272334bc4a560000e8736860b4e6980d3f865b9abea3baee3bfee41ab1894bd6R168

But it'll make android issue like bottom screen shot.
스크린샷 2024-01-20 오후 1 59 33

So I think if we want to fully support codegen, we need to change android's native codes about headers prop?
I want to know your opinion about this issue.
Cheers.

@KrzysztofMoch
Copy link
Member

Yeah, seems like we can't use Record<string, string> with codegen. We should pass it as an array and then on native side convert it to Map to decrease number of changes in codebase
https://github.com/react-native-video/react-native-video/blob/3858a15b4268ae54d5b97c036d86b05aaf31bcf9/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java#L152-L161
So, change expected type to Array and convert it to Map<String, String>, WDYT ?

@yungblud
Copy link
Contributor Author

yungblud commented Jan 21, 2024

@KrzysztofMoch
Yeah, we already have code about that.
I will show you code fragment about that changes of setSrc's parsing headers part.

        Map<String, String> headers = new HashMap<>();
        ReadableArray propSrcHeadersArray = (src.hasKey(PROP_SRC_HEADERS)) ? src.getArray(PROP_SRC_HEADERS) : null;
        if (propSrcHeadersArray != null) {
            if (propSrcHeadersArray.size() > 0) {
                for (int i = 0; i < propSrcHeadersArray.size(); i++) {
                    ReadableMap current = propSrcHeadersArray.getMap(i);
                    String key = current.hasKey("key") ? current.getString("key") : null;
                    String value = current.hasKey("value") ? current.getString("value") : null;
                    if (key != null && value != null) {
                        headers.put(key, value);
                    }
                }
            }
        }

And also we should consider setDRM too. (but approach would be similar)

So if you are okay about that code fragment, I will make an additional commit about this issue.

src/types/video.ts Outdated Show resolved Hide resolved
selectedAudioTrack?: SelectedTrack;
selectedTextTrack?: SelectedTrack;
selectedVideoTrack?: SelectedVideoTrack; // android
selectedAudioTrack?: SelectedTrackType;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't undestand why you did this change ...
SelectedTrack is an object representing all possible values to select a track where SelectedTrackType is an enum representing which kind of track selection can be used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I couldn't fully understand your point.
So you want to use typescript's enum value as selectedAudioTrack's type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, mate.
I think I just deleted typescript enum types and replaced them from codegen types to recycle codegen types.
Just naming and few types change for codegen types.
I think there would have no problem?

Let me know your opinion.
@freeboub

Copy link
Collaborator

Choose a reason for hiding this comment

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

Here is doc:
selectedAudioTrack
Configure which audio track, if any, is played.

selectedAudioTrack={{
type: Type,
value: Value
}}

SelectedAudioTrack is an object
SelectedAudioTrack.type is the enum you use.

Is that clearer ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use https://github.com/react-native-video/react-native-video/pull/3487/files#diff-70773b05560f0897b24b4baa0ed114158fd50e075c0c76de43cc30b90043eb80R75 this type from 'specs/VideoNativeComponent.tsx'

스크린샷 2024-01-30 오전 10 38 17

We cannot use typescript's enum type with codegen. It can't be possible.
So I recycled above codegen type for Selected**Track prop types.

I think you want to consider DX for developers by handling type as enum.
I think it can be possible, but I'm not sure. I will have a try.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@freeboub Can you check this commit?
I've handled some issue about this comments.
d1a858a

I think we have to choose between

  • remain docs and modify some types like above commit
  • change docs and give up enum types

Let me know your opinion. that commit can be reverted.

src/Video.tsx Show resolved Hide resolved
src/utils.ts Show resolved Hide resolved
@@ -0,0 +1,536 @@
/* eslint-disable @typescript-eslint/ban-types */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it mandatory to move this file ?
It makes review harder ... (I think you remove and add instead of git mv)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's because of handling {} on codegen.
I wanted to use Readonly but it cannot be possible.

But, I found another issue on OnReceiveAdEventData while I am looking this issue.
OnReceiveAdEventData['data'] type should be handled as array type I guess.
Because codegen cannot parse Record<string, string> type.
I think I just handle that type as just {} and I missed it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or, we have to define OnReceiveAdEventData['data'] type as Readonly object if we can define what key and value are expected.

Copy link
Member

Choose a reason for hiding this comment

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

@yungblud I think the point is that instead of deleting and adding a file (using git add), you should use git mv to move the file - this keeps the diff between files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@KrzysztofMoch Thanks. That was my mistake.
I will try that!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I think I cannot do mv file clearly.
I tried multiple times but it's difficult to show just "mv" on file changes.

@freeboub
Copy link
Collaborator

And thank you for extracting in smaller PR ! 🙏

@yungblud
Copy link
Contributor Author

And thank you for extracting in smaller PR ! 🙏

Thanks my pleasure.

@KrzysztofMoch
Copy link
Member

KrzysztofMoch commented Jan 22, 2024

So if you are okay about that code fragment, I will make an additional commit about this issue.

@yungblud for me its okay 🙌

@yungblud
Copy link
Contributor Author

@KrzysztofMoch @freeboub
67c648e
Can you guys check this new commit?
This commit is for this issue

And I would be happy if you guys check again my comments.
Thanks.

Copy link
Collaborator

@freeboub freeboub left a comment

Choose a reason for hiding this comment

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

few minor comment.
Regarding to the sample, won't it make sens to merge the new arch with basic sample?
I don't request it now, I am just asking ! I am afraid it will be painful to maintain multiple sample.

@yungblud
Copy link
Contributor Author

few minor comment. Regarding to the sample, won't it make sens to merge the new arch with basic sample? I don't request it now, I am just asking ! I am afraid it will be painful to maintain multiple sample.

Yeah maybe it would be happier. (if we can)
Let me consider them too. Cheers.
@freeboub

@@ -80,7 +80,7 @@ export enum SelectedTrackType {

export type SelectedTrack = {
type: SelectedTrackType;
value?: string | number;
Copy link
Collaborator

@freeboub freeboub Jan 30, 2024

Choose a reason for hiding this comment

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

Value can be a number in the code ... it is used when we select by index.
Is it problematic for codegen ? I review last commit and it seems working with Int Type !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, all types in src/types/video.ts are for JS layer's prop types.
The reason I removed number is I did want to sync with codegen types of SelectedTrack.
Such as this https://github.com/react-native-video/react-native-video/pull/3487/files/d1a858a590339b48d5430fbe8b8769f8f1921bd6#diff-70773b05560f0897b24b4baa0ed114158fd50e075c0c76de43cc30b90043eb80R85

스크린샷 2024-01-31 오전 10 19 48

I think Codegen do not allow mixed types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we have to change docs content of this types.
I am not sure what is the best option. But codegen do not allow mixed types.
So maybe we have to change docs?
Let me know your opinion @freeboub

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok, I can propose you this change:

  • keep current behavior fo external API
  • move the value to string only in native bindings (then string To Int in native code)
  • do the wrapping in Video.js to convert the int to string

This is the ideal change. but is you really prefer keep it as string only (even in external API), just notice this is a breaking change. (but you need anyway to change the native code)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay I will have a check.
Thanks for the suggestions!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@freeboub hello, sorry for the late reply.
I've implemented your suggestions on this commit 2ef456a

Can you have a look?
If I didn't catch your suggestions, let me know.

@yungblud
Copy link
Contributor Author

yungblud commented Mar 1, 2024

@freeboub Hey, thanks for the reviewing my PR.
I've resolved merge conflicts from master branch.

@freeboub
Copy link
Collaborator

freeboub commented Mar 1, 2024

This PR is OK for me @KrzysztofMoch can you please double check ?
BTW @KrzysztofMoch do you think we shall merge it before or after next release ? (I would say just after)

@KrzysztofMoch
Copy link
Member

KrzysztofMoch commented Mar 1, 2024

Okay, will check that
Yes, I think we should merge it and release in next release for our safety

Copy link
Member

@KrzysztofMoch KrzysztofMoch left a comment

Choose a reason for hiding this comment

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

I have tested both iOS & android in basic example - and it's work perfectly
Now @yungblud you can leave it to use, we will release in our time 😄
Thanks for your effort!

@yungblud I have one question, I guess that with this change we will drop support for older versions of react-native. Do you know maybe what is the older version that we can support?

@yungblud
Copy link
Contributor Author

yungblud commented Mar 3, 2024

I have tested both iOS & android in basic example - and it's work perfectly Now @yungblud you can leave it to use, we will release in our time 😄 Thanks for your effort!

@yungblud I have one question, I guess that with this change we will drop support for older versions of react-native. Do you know maybe what is the older version that we can support?

@KrzysztofMoch Hey, thanks for detailed review of my PR.
Hmm, if you want to consider deprecate older versions of react-native, I think minimum "codegen available" version would be the best option.

https://reactnative.dev/blog/2022/03/30/version-068#opting-in-to-the-new-architecture
I think 0.68.0 would be the first version that RN was released with "New Architecture" support.
So I would suggest set minimum version of RN to 0.68.0 for react-native-video.

@freeboub
Copy link
Collaborator

freeboub commented Mar 6, 2024

I am ready to merge, but there are still conflicts ...
Please merge with master, it will be the next merged PR !

@yungblud
Copy link
Contributor Author

yungblud commented Mar 6, 2024

@freeboub Hello! Conflicts were simple. had no problem.
I've resolved it by merging upstream/master.

@KrzysztofMoch KrzysztofMoch merged commit b33e6df into TheWidlarzGroup:master Mar 7, 2024
11 checks passed
@KrzysztofMoch
Copy link
Member

KrzysztofMoch commented Mar 7, 2024

it will be the next merged PR !

@freeboub I merged it to avoid next possible conflicts (if you are not happy with it please revert)

@freeboub
Copy link
Collaborator

freeboub commented Mar 7, 2024

@KrzysztofMoch I am happy with that :)

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.

3 participants