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

feat: support Fabric #1754

Closed
wants to merge 58 commits into from
Closed

feat: support Fabric #1754

wants to merge 58 commits into from

Conversation

WoLewicki
Copy link
Member

@WoLewicki WoLewicki commented Apr 20, 2022

PR adding support for Fabric to the library. See #1804 for the working version for both platforms.

One of the main changes that can affect old architecture is stringifying all props of type NumberProp since codegen does not allow for props to have type string or number. It would be best to find a way around it since it might cause issues e.g. in libraries like react-native-reanimated where we want to skip the render part and change props directly on the native side. It seems not to be problematic with RN Animated since on Fabric setNativeProps is not supported so probably all changes even with nativeDriver are going through a render but I might be wrong.

Another one is iOS view hierarchy structure. Right now all ComponentViews have their corresponding svg elements as contentViews. The mountChildComponentView and unmountChildComponentView methods of those ComponentViews have been changed such that the views are added directly as children of contentViews of their parents so we keep the view structure from the old architecture. It was working well, but recently I discovered that when ComponentViews are not present in the native view hierarchy, the responder system stopped working. Due to this, I also add ComponentViews in a different view hierarchy just so they are present there, making the responder system work correctly.

@AlirezaHadjar
Copy link

Hi guys, thank you for working on this pr
Is there any estimated time for merging it into master?

@WoLewicki
Copy link
Member Author

@AlirezaHadjar thanks for kind words. It is unfortunately very hard to estimate the time needed to merge it since there are many components which need to be transferred and also there can be many implementation details in Fabric which we are not aware of at the moment that can slow down the process.

@mateosilguero
Copy link

@WoLewicki Could i help you doing anything ?

@WoLewicki
Copy link
Member Author

@mateosilguero thanks for wanting to contribute! One thing I can think of at the moment is a research for the ability to pass number or string to the native side via codegen. Right now I have to stringify all props such as x or width (see e.g. https://github.com/react-native-svg/react-native-svg/pull/1754/files#diff-874235021936bd582576fd90475e171236f75499fe25e916a37e8bce29762f7eR27) since there can be only one type of argument passed in the codegen interface (see e.g. https://github.com/react-native-svg/react-native-svg/pull/1754/files#diff-51c3f8a2d2280f5c9e099d6a7f0a4fe6bf1750c2be83ea7f0a40ccbb1a5da4a5R69).

@sebasg0
Copy link

sebasg0 commented Jul 8, 2022

Hi @WoLewicki , sorry to bother but there’s no plans to continue this implementation in a near future?

@WoLewicki
Copy link
Member Author

@sebasg0 I ended fixing Fabric issues in react-native-screens for now and I am going back to react-native-svg so be ready for some updates 😅

@skurgansky-sugarcrm
Copy link

@WoLewicki good news

@WoLewicki WoLewicki marked this pull request as ready for review July 22, 2022 09:21
@WoLewicki
Copy link
Member Author

Hi 👋 I added a second PR, pointing to this branch, with most of Android changes here: #1804. I think it is now ready to review, for sure there are many things that should be done better. Please test it and submit any bug you encounter 🚀

Copy link
Member

@j-piasecki j-piasecki left a comment

Choose a reason for hiding this comment

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

I think I found all white-space errors there

*/

project.ext.react = [
enableHermes: false, // clean and rebuild if changing
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't Hermes be enabled? (It's not changed in the Android PR).

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, it is not enabled in react-native-screens: https://github.com/software-mansion/react-native-screens/blob/7e4a348bd360ecc5aa7ba378a8adbdc3dff9fc37/FabricTestExample/android/app/build.gradle#L81, do you think it would change anything regarding potential bugs?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure, In the Sample new arch app it's one of the steps to enable it, but if it works here and in react-native-screens then it's fine, I guess?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll enable it as it is a recommended step 👍

<Text>TEST</Text>
</>
);
}
Copy link
Member

Choose a reason for hiding this comment

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

New line 🙂

},
}),
},
};
Copy link
Member

Choose a reason for hiding this comment

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

New line 🙂

{
"name": "FabricExample",
"displayName": "FabricExample"
}
Copy link
Member

Choose a reason for hiding this comment

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

New line 🙂

Comment on lines +104 to +106
static SVGLength from(double number) {
return new SVGLength(number);
}
Copy link
Member

Choose a reason for hiding this comment

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

It looks like indentation is wrong here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I will have to apply some kind of formatter for JS, Java and iOS files.

return facebook::jni::initialize(vm, [] {
facebook::react::RNSvgComponentsRegistry::registerNatives();
});
}
Copy link
Member

Choose a reason for hiding this comment

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

New line 🙂

};

} // namespace react
} // namespace facebook
Copy link
Member

Choose a reason for hiding this comment

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

New line 🙂


type ComponentType = HostComponent<NativeProps>;

export default (codegenNativeComponent<NativeProps>('RNSVGCircle', {}): ComponentType);
Copy link
Member

Choose a reason for hiding this comment

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

New line here and in every other *NativeComponent.js file 🙂

@@ -151,6 +151,17 @@ export function extract(instance: Object, props: Object & { style?: [] | {} }) {
return extractProps(propsAndStyles(props), instance);
}

export function stringifyPropsForFabric(props: { [key: string]: NumberProp | undefined | null; }): { [key: string]: string; } {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this function is beeing called regardless of whether Paper or Fabric is used. Are the props it's generating used only on Fabric or on Paper too?

Copy link
Member Author

Choose a reason for hiding this comment

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

For now the implementation makes the change of all NumberProp props to string on both archs. I would prefer not to do it but I cannot find a way around it for now. I could add checks for Fabric in all of those places if we don't find another way to handle it.

@WoLewicki
Copy link
Member Author

You can check #1821 for the version of this PR without ComponentView abstraction usage.

@ShivamJoker
Copy link

It would be great to get this merged. I am migrating my apps to new arch. Thanks to all the contributors :)

WoLewicki added a commit that referenced this pull request Aug 11, 2022
Version of #1754 without usage of ComponentViews. It seems like a more proper way, but introduces the necessity of clearing whole state of each component on recycling for it not to be used when view is recycled.

Still known problems:

We stringify props of type NumberProp since codegen only accepts props of a single type. It is the fastest way of dealing with it, but maybe there could be a better way to handle it.
Image resolving should be probably handled the same as in RN core
SvgView needs to set opaque = NO so it is does not have black background (it comes from the fact that RCTViewComponentView overrides backgroundColor setter which in turn somehow messes with the view being opaque). All other svg components do it already so maybe it is not such an issue.
transform prop won't work when set natively since it is not parsed in Fabric
@kylegillen
Copy link

Great work y'all. Any chance we can get this merged please? Would love to test it out 🙏

@WoLewicki
Copy link
Member Author

I am closing this PR since #1821 has been merged. After merging #1804 and probably #1782, I will release a new major version with Fabric available in the library so everyone can test it and submit any issues found 🎉

@WoLewicki WoLewicki closed this Aug 12, 2022
aaron1234567890123 added a commit to aaron1234567890123/react-native-svg that referenced this pull request Jun 8, 2024
Version of software-mansion#1754 without usage of ComponentViews. It seems like a more
proper way, but introduces the necessity of clearing whole state of
each component on recycling for it not to be used when view is
recycled.

Still known problems:

We stringify props of type NumberProp since codegen only accepts props
of a single type. It is the fastest way of dealing with it, but maybe
there could be a better way to handle it.
Image resolving should be probably handled the same as in RN core
SvgView needs to set opaque = NO so it is does not have black
background (it comes from the fact that RCTViewComponentView overrides
backgroundColor setter which in turn somehow messes with the view
being opaque). All other svg components do it already so maybe it is
not such an issue.
transform prop won't work when set natively since it is not parsed in
Fabric
aaron1234567890123 added a commit to aaron1234567890123/react-native-svg that referenced this pull request Jun 8, 2024
Version of software-mansion#1754 without usage of ComponentViews. It seems like a more
proper way, but introduces the necessity of clearing whole state of
each component on recycling for it not to be used when view is
recycled.

Still known problems:

We stringify props of type NumberProp since codegen only accepts props
of a single type. It is the fastest way of dealing with it, but maybe
there could be a better way to handle it.
Image resolving should be probably handled the same as in RN core
SvgView needs to set opaque = NO so it is does not have black
background (it comes from the fact that RCTViewComponentView overrides
backgroundColor setter which in turn somehow messes with the view
being opaque). All other svg components do it already so maybe it is
not such an issue.
transform prop won't work when set natively since it is not parsed in
Fabric
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.