Repository navigation
Refactor React code to use functional components and hooks? #4345
RobJacobson
started this conversation in
General
Replies: 1 comment
|
Thanks Rob, and thanks for the fixes so far! Open to it, but carefully: our Camera rewrite to hooks caused a long tail of regressions, so readability alone isn't worth breaking anything. Rules:
If the pilot goes smoothly we can do the rest of the layers. Small PRs please. Style-wise, see AGENTS.md in the repo. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Greetings! I'm using @rnmapbox for several in-development projects. Thanks for maintaining this!
I submitted a few bug-fixes that were accepted. (HTH.) I would love to get more involved. Are there any high-priority issues to address? I'm mostly a React/Expo developer, not really familiar with Swift or Kotlin, but I can fake it with the assistance of ChatGPT.
I'd like to raise "a modest proposal," so to speak. Specifically, have you considered refactoring the codebase to use modern React functional components and hooks, instead of class-based components? Whenever I attempt to read the old coding style, it just melts my mind. I have to remember the ancient coding conventions and how they map to modern concepts.
There are currently 24 modules that use the class-based approach, as summarized below. The lowest-hanging fruit would be the twelve layers classes, since they have considerable overlap.
If there's any appetite for this, I could take a crack at this. This would be directed at using modern React conventions for readability and future maintenance, without any breaking changes. I would add unit tests with ChatGPT to protect against regressions, and then use ChatGPT to automate this to the maximum extent possible.
Please let me know if this would be valuable. If so, I could start with the twelve layer classes and submit them for feedback. Also, please let me know if you have a specific style-guide that I should follow for comments, code organization, etc.
Cheers,
Rob
Files in scope
There are currently 24 modules that use the class-based approach:
src/components/Annotation.tsxsrc/components/BackgroundLayer.tsxAbstractLayerinheritance and retain native prop conversion.__tests__/components/BackgroundLayer.test.js.src/components/Callout.tsx__tests__/components/Callout.test.tsx.src/components/CircleLayer.tsxAbstractLayerinheritance and retain native prop conversion.__tests__/components/CircleLayer.test.js.src/components/FillExtrusionLayer.tsxAbstractLayerinheritance and retain style and source props.src/components/FillLayer.tsxAbstractLayerinheritance and retain style and source props.src/components/HeatmapLayer.tsxAbstractLayerinheritance and retain native prop conversion.__tests__/components/HeatmapLayer.test.js.src/components/HillshadeLayer.tsxAbstractLayerinheritance and retain style and source props.src/components/ImageSource.tsxAbstractSourceinheritance; preserve child cloning and native refs.src/components/Images.tsxsrc/components/LineLayer.tsxAbstractLayerinheritance and retain style and source props.src/components/MapView.tsx__tests__/components/MapView.test.js; add ref and lifecycle cases.src/components/ModelLayer.tsxAbstractLayerinheritance and retain style and source props.src/components/PointAnnotation.tsxsrc/components/RasterArraySource.tsxAbstractSourceinheritance and retain URL, tile, and child props.src/components/RasterDemSource.tsxAbstractSourceinheritance and preserve constructor-derived URL props.src/components/RasterLayer.tsxAbstractLayerinheritance and retain style and source props.src/components/RasterParticleLayer.tsxAbstractLayerinheritance and retain style and source props.src/components/RasterSource.tsxAbstractSourceinheritance and preserve URL-derived props and children.src/components/ShapeSource.tsxsetNativeProps, event handling, and child behavior.src/components/SkyLayer.tsxAbstractLayerinheritance and retain style and source props.src/components/SymbolLayer.tsxAbstractLayerinheritance and retain style, source, and children behavior.__tests__/components/SymbolLayer.test.js.src/components/UserLocation.tsx__tests__/components/UserLocation.test.js; add subscription cleanup cases.src/components/VectorSource.tsxAbstractSourceinheritance; preserve native ref and press event handling.src/components/AbstractLayer.tsxsrc/components/AbstractSource.tsxsetNativeProps.src/components/NativeBridgeComponent.tsxMapView,ShapeSource, andPointAnnotation.All reactions