Skip to content

feat(ios): make CoreSVG decoder opt-in - #606

Open
oleksandrzavarzin-callstack wants to merge 4 commits into
callstack:mainfrom
oleksandrzavarzin-callstack:codex/issue-565-svg-opt-in
Open

oleksandrzavarzin-callstack wants to merge 4 commits into
callstack:mainfrom
oleksandrzavarzin-callstack:codex/issue-565-svg-opt-in

Conversation

@oleksandrzavarzin-callstack

Copy link
Copy Markdown
Contributor

Closes #565. It is a continuation of @thiagobrez's work from #566.

Summary

The private-CoreSVG decoder is now opt-in on Apple platforms. By default, no SVG source is compiled or linked, and the decoder is never registered with React Native's app-wide image loader.

 CocoaPods (podspec)
-  ios/SVG/** always compiled
+  ios/SVG/** excluded unless $RNBottomTabsEnableSVG = true
 SwiftPM (Package.swift)
-  ios/SVG compiled into react_native_bottom_tabs
+  BottomTabsSVG target only when RN_BOTTOM_TABS_ENABLE_SVG=1
 Expo config plugin
+  { "enableSVG": true } writes $RNBottomTabsEnableSVG = true into the Podfile
 codegen (package.json)
-  modulesConformingToProtocol: RCTImageDataDecoder → SvgDecoder
+  (removed, so imageDataDecoderClassNames is empty)

With the flag set, the tab view decodes SVG icons itself:

loadIcons
  if SVG request            → SVGIconLoader.decode → updateIcon
  else RCTImageLoader.load
    on error (opt-in only)  → SVGIconLoader.decode → updateIcon   # extensionless SVG URLs

How to opt in:

Setup Opt-in
CocoaPods $RNBottomTabsEnableSVG = true in the Podfile, before React Native configures pods, then pod install
Expo prebuild ["react-native-bottom-tabs", { "enableSVG": true }]
SwiftPM RN_BOTTOM_TABS_ENABLE_SVG=1 in the environment when SwiftPM resolves packages

Changes on top of #566:

  • Rebased on main.
  • SwiftPM opt-in in Package.swift. SvgDecoder.h is removed from ios/include/module.modulemap.
  • The verification artifacts (artifacts/issue-565/) are removed from the repository.
  • TabViewProvider.swift is split for SwiftLint. The SVG helpers moved to ios/SVGIconLoader.swift.

Results

Tested with Xcode 27.0 on an iPhone simulator with iOS 26.5.

  • Before (main): every iOS app links the CoreSVG code. CoreSVGWrapper and the base64 symbol names are in the binary.
  • After, default: none of CoreSVGWrapper, SvgDecoder, CGSVGDocument, RNBottomTabsDecodeSVGData, or the base64 literals are in the app binary. RCTTabViewComponentView is present as a control. The Pods project has 0 ios/SVG files, and imageDataDecoderClassNames is empty. On the simulator, SF Symbol and PNG icons render, and SVG tabs show their titles with no icon.
  • After, opt-in: _RNBottomTabsDecodeSVGData, CoreSVGWrapper, and the base64 literals are present. CocoaPods adds exactly CoreSVG.{h,mm} and SvgDecoder.{h,mm}. Local and remote SVG tab icons render on the simulator.
default SF Symbols default SVG example (titles only) opt-in local SVG opt-in remote SVG
default-sf default-svg svg-local svg-remote
  • Expo plugin, with four expo prebuild --platform ios runs: without the option there is no flag. With enableSVG: true, there is one generated block right after platform :ios. Removing the option removes the block.
  • swift package dump-package without the variable has no BottomTabsSVG target. With RN_BOTTOM_TABS_ENABLE_SVG=1, it adds the target and the Swift define.
  • yarn lint: 0 errors.
  • yarn test: passes. It includes the new svg_configuration_test.rb with 3 runs and 7 assertions.
  • yarn typecheck: passes.
  • SwiftLint 0.65.1: 0 errors, and 53 warnings against 54 on main.

Before Merging

This is a breaking default, so it ships as a major changeset. After a release, apps that update depend on the new default.

Blast Radius: iOS SVG users

  • Apps that use SVG tab icons on Apple platforms lose those icons after the upgrade until they add the flag and rebuild.
  • Apps that used a plain React Native <Image> with an SVG source lose that as well. The decoder was app-wide before. It now serves only tab icons, even with the flag.
  • SwiftPM: Xcode reads RN_BOTTOM_TABS_ENABLE_SVG only from its own environment. If Xcode was started from the Dock, a variable set in a shell does not reach it.

This branch has not been deployed

No deployments
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.

iOS: allow opting out of the private-CoreSVG SVG decoder (exclude_files by default, or an opt-in flag)

2 participants