8000 fix: support use_frameworks! by coolsoftwaretyler · Pull Request #11 · dominicstop/react-native-ios-utilities · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: support use_frameworks! #11

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

Conversation

coolsoftwaretyler
Copy link
Contributor
@coolsoftwaretyler coolsoftwaretyler commented Nov 30, 2024

Closes #10

Xcode will replace hyphens with underscores when building Frameworks. So if you install this project with:

USE_FRAMEWORKS="static" pod install

All of the generated paths will be converted from react-native-ios-utilities to react_native_ios_utilities.

This PR uses a preprocessor directive to check if the imported headers exist at the path with underscores. If they do, then we use the underscore imports. If not, we use the old ones.

Other options to consider

  1. It might make sense to just rename the module entirely to be something like ReactNativeIosUtilities to be more conventional.
  2. You could use module_name to set the name to something different, but there's no way to include hyphens in the module name for bridging, so there would still be this conditional logic.
  3. Set up a project-specific macro to do this conditional work
  4. Update the header search paths so they include both react-native-ios-utilities and react_native_ios_utilities. That way you could just use relative paths to the headers. I strongly considered this option, but I don't love the idea of collision possibilities or ambiguity.

So here, I just went through file-by-file and cleaned up the headers. This fixes one problem (headers for the project being incorrect), but leaves another issue (I'll write about that later on).

Here is an example of one of the errors I've observed on the example app in master, when USE_FRAMEWORKS is either static or dynamic:

Screenshot 2024-11-29 at 6 23 01 PM

With this PR, these errors go away (they're pervasive in all the header imports).

Remaining issues

Unfortunately, I'm still running into some issues in the React Native UIManager class, which is throwing this error:

/Users/tylerwilliams/Library/Developer/Xcode/DerivedData/IosUtilitiesExample-gxuxatrkcpajlmgczqsxbhasxken/Build/Products/Debug-iphonesimulator/React-Fabric/React_Fabric.framework/Headers/react/renderer/uimanager/UIManager.h:17:10 'react/renderer/consistency/ShadowTreeRevisionConsistencyManager.h' file not found

I found a similar looking issue in Expo: expo/expo#31092, which they solved by adding React-rendererconsistency as a dependency.

However, that patch doesn't change anything, and I actually see that being installed through Pods already. I'm guessing there's some problem with the header/framework lookup paths, but I'm stumped at this point. @dominicstop - I would love your thoughts on that. Happy to continue doing the work if you have any insights into how to troubleshoot that.

Checking locally

  1. Pull down this branch
  2. Clean dependencies and reinstall
  3. cd example/ios
  4. pod deintegrate && rm -rf Pods/ && rm -rf Podfile.lock && NO_FLIPPER="1" USE_FRAMEWORKS="static" RCT_NEW_ARCH_ENABLED="1" pod install --repo-update && open IosUtilitiesExample.xcworkspace (just to be like, super sure about all of the dependencies being clean
  5. Build
  6. See the new missing header error.

@@ -17,7 +17,7 @@
"react-native": "0.75.2",
"react-native-codegen": "0.71.3",
"react-native-safe-area-context": "^4.10.8",
"react-native-screens": "^3.34.0"
"react-native-screens": "4.3.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@coolsoftwaretyler
Copy link
Contributor Author
coolsoftwaretyler commented Nov 30, 2024

Oh hey I got a bit further. In c8d230c, the build works with USE_FRAMEWORKS="static", but now I'm getting a new runtime error:

Thread 1: "View was already initialized: <RNIWrapperViewContent: 0x11a634f50; frame = (0 0; 0 0); layer = <CALayer: 0x600000362d40>>"

Progress!

Runtime error in Xcode, it's in the 'main' tab

@coolsoftwaretyler coolsoftwaretyler force-pushed the twilliams/fix-framework-support-in-header-paths branch from a9c4c9f to c8d230c Compare November 30, 2024 05:06
@coolsoftwaretyler
Copy link
Contributor Author

Maybe related to #9. I'll try that patch later.

8000

@coolsoftwaretyler
Copy link
Contributor Author

Yup, that did it!

@coolsoftwaretyler
Copy link
Contributor Author

Cherry-picked 8fb4717 into this branch.

I'll check that everything works without frameworks, with dynamic frameworks, and without the new arch as well.

@coolsoftwaretyler coolsoftwaretyler changed the title fix: update header paths for use_frameworks support fix: support use_frameworks! Nov 30, 2024
@coolsoftwaretyler
Copy link
Contributor Author

Ok, I've got it working with USE_FRAMEWORKS="static", without frameworks, and across new/old arch.

The only thing that isn't working right now is USE_FRAMEWORKS="dynamic", which gets a runtime error from main.c:

Thread 1: "[<RCTView 0x10d8ba570> valueForUndefinedKey:]: this class is not key value coding-compliant for the key reactEventHandler."

An abort signal terminated the process. Such crashes often happen because of an uncaught exception or unrecoverable error or calling the abort() function.

My intuition is that some difference in using dynamic libraries means that we're missing some linking for RCTView or something.

I'll keep investigating, but I'd be happy for additional insight in the meantime. Or perhaps it makes sense to merge this and #9 so that people can at least use static frameworks, and handle dynamic frameworks in a separate PR.

@coolsoftwaretyler
Copy link
Contributor Author
coolsoftwaretyler commented Nov 30, 2024

Sweet, with 08b9798, I've got it working with:

  1. New arch, static frameworks
  2. New arch, dynamic frameworks
  3. New arch, no frameworks
  4. Old arch

The last change here was to update the macros in ios/Sources/RNIBaseView/RNIBaseViewUtils.h to no-op when trying to access reactPropHandler and reactEventHandler.

With static libraries, these macros get ignored at compile time. But with dynamic libraries, they still get evaluated, so we need to provide them a way to not try and access the old architecture properties there safely.

@dominicstop - I think this is good to be reviewed now. Happy to make any adjustments as needed.

@dominicstop
Copy link
Owner

hello, i apologize for the very late response and thank you very much for contributing to this library. i will merge and release a new version w/ your changes.

not a lot ppl contribute to my libraries, so i am inexperienced with handling PR's; this is just a future reminder for myself not to press the "merge and rebase" button (again).

@coolsoftwaretyler
Copy link
Contributor Author

Thanks @dominicstop! No problem at all. Love what you've done here and I appreciate your time.

I'll keep an eye out for future releases. Let me know if there's any regressions, or if there's anything else I can help with - either in the code, or if you need a hand working with community contributions.

@dominicstop
Copy link
Owner

hello, i added a workflow action to test out paper/fabric + static library/dynamic framework

i updated the imports again, and it still seems to work ok. please let me know if there are any potential regressions

Screenshot 2024-12-06 at 3 35 32 AM

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.

'react-native-ios-utilities/RNIRegistrableView.h' file not found
3 participants
0