Skip to content

[iOS] Build fails on Xcode 26.2: constexpr with Objective-C literals in RNSScreenStackHeaderConfig.mm #3549

@awais-wego

Description

@awais-wego

Description

iOS builds fail on Xcode 26.2 (and likely Xcode 26.x) with a compilation error in RNSScreenStackHeaderConfig.mm. The error occurs because constexpr cannot be used with Objective-C literals, which Xcode 26's stricter C++ compiler now enforces.

Environment

Package Version
react-native-screens 4.17.0 - 4.18.0
React Native 0.77.0
Xcode 26.2
iOS Deployment Target 15.1+
Platform iOS

Note: This issue does NOT affect versions 4.19.0+, which have a different (codegen-related) issue.

Error

❌ /path/to/node_modules/react-native-screens/ios/RNSScreenStackHeaderConfig.mm:42:23:
Constexpr variable 'DEFAULT_TITLE_FONT_SIZE' must be initialized by a constant expression
static constexpr auto DEFAULT_TITLE_FONT_SIZE = @17;

Full compilation output:

CompileC /Users/.../RNSScreenStackHeaderConfig.o
/Users/.../node_modules/react-native-screens/ios/RNSScreenStackHeaderConfig.mm
normal arm64 objective-c++
com.apple.compilers.llvm.clang.1_0.compiler (in target 'RNScreens' from project 'Pods')

Root Cause

In ios/RNSScreenStackHeaderConfig.mm (lines 42-43):

static constexpr auto DEFAULT_TITLE_FONT_SIZE = @17;
static constexpr auto DEFAULT_TITLE_LARGE_FONT_SIZE = @34;

Problem:
Objective-C literals like @17 and @34 are runtime NSNumber objects
C++ constexpr requires compile-time constant expressions
Xcode 26 enforces this strictly (earlier Xcode versions were lenient)

Proposed Solution
Change the declarations to use standard Objective-C constant pointers:

static NSNumber *const DEFAULT_TITLE_FONT_SIZE = @17;
static NSNumber *const DEFAULT_TITLE_LARGE_FONT_SIZE = @34;

Why this works:
static NSNumber *const = "constant pointer to NSNumber object"
This is the standard Objective-C pattern for compile-time constant pointers to runtime objects
No runtime behavior changes (same values, same usage)
Reproduction Steps
Set up React Native 0.77.0 project with react-native-screens 4.17.0 or 4.18.0
Use Xcode 26.2
Attempt to build for iOS: cd ios && pod install && xcodebuild ...
Observe compilation failure in RNSScreenStackHeaderConfig.mm

Minimal reproduction:

npx @react-native-community/cli init TestApp --version 0.77.0
cd TestApp
npm install [email protected]
cd ios && pod install
xcodebuild -workspace TestApp.xcworkspace -scheme TestApp -configuration Release

Impact
❌ Blocks all iOS builds on Xcode 26.2
❌ Affects CI/CD pipelines using Xcode 26.2
❌ Prevents app updates for developers who upgraded Xcode
✅ Android builds unaffected

Current Workaround
Using patch-package to apply the fix locally:
patches/react-native-screens+4.18.0.patch:

diff --git a/node_modules/react-native-screens/ios/RNSScreenStackHeaderConfig.mm b/node_modules/react-native-screens/ios/RNSScreenStackHeaderConfig.mm
index cfe3941..17201ca 100644
--- a/node_modules/react-native-screens/ios/RNSScreenStackHeaderConfig.mm
+++ b/node_modules/react-native-screens/ios/RNSScreenStackHeaderConfig.mm
@@ -39,8 +39,9 @@
namespace react = facebook::react;
#endif // RCT_NEW_ARCH_ENABLED

-static constexpr auto DEFAULT_TITLE_FONT_SIZE = @17;
-static constexpr auto DEFAULT_TITLE_LARGE_FONT_SIZE = @34;
+// Fixed for Xcode 26 compatibility - constexpr with Obj-C literals is not valid
+static NSNumber *const DEFAULT_TITLE_FONT_SIZE = @17;
+static NSNumber *const DEFAULT_TITLE_LARGE_FONT_SIZE = @34;

#if !defined(RCT_NEW_ARCH_ENABLED)
// Some RN private method hacking below. Couldn't figure out better way to access image data

Questions for Maintainers
Is this already fixed in the main branch?
Would you accept a PR targeting main with this fix?
Should this be backported to 4.18.x as a patch release (4.18.1)?
Are you planning to drop Xcode <26 support soon, making this a non-issue?
Additional Context
This issue is separate from the codegen issues in #3496 and #3526
Those issues affect 4.19.0-4.20.0 with React Native codegen
This constexpr issue affects 4.17.0-4.18.0 with native compilation
The fix is minimal (2 lines) and follows Objective-C best practices

Testing
With the patch applied:
✅ iOS build succeeds on Xcode 26.2
✅ App runs normally on iOS 15.1 - 18.x
✅ No runtime behavior changes
✅ CI/CD pipeline works correctly
I'm happy to submit a PR if this is deemed valuable and maintainers can provide guidance on which branch to target.

References
Similar constexpr issues in other libraries:
StackOverflow: iOS build fails with constexpr error
Apple's Xcode 26 Release Notes (stricter C++ compliance)
Related (but different) closed issues: #3496, #3526 (codegen, not constexpr)

Steps to reproduce

⚠️ REPRODUCTION REQUIRES XCODE 26.2 - Native Build-Time Compiler Error

This cannot be reproduced in Expo Snack (doesn't compile native iOS code). This is a deterministic build failure that occurs during Xcode compilation.

Prerequisites:

  • Xcode 26.2 or later (critical - older versions won't show the error)
  • macOS 15.x (Sequoia)
  • Node.js 18+
  • CocoaPods 1.15+

Reproduction Steps:

1. Create new React Native project

npx @react-native-community/cli@latest init XcodeRepro --version 0.77.0
cd XcodeRepro

2. Install the affected version

npm install [email protected]

3. Install iOS dependencies

cd ios
pod install
cd ..

4. Attempt to build (will fail on Xcode 26.2)

cd ios
xcodebuild -workspace XcodeRepro.xcworkspace
-scheme XcodeRepro
-configuration Release
-sdk iphoneos
archive

Expected: Build fails with constexpr error in RNSScreenStackHeaderConfig.mm:42

Error Output:

CompileC [...]/RNSScreenStackHeaderConfig.o [...]/RNSScreenStackHeaderConfig.mm normal arm64 objective-c++ com.apple.compilers.llvm.clang.1_0.compiler

❌ error: Constexpr variable 'DEFAULT_TITLE_FONT_SIZE' must be initialized by a constant expression
static constexpr auto DEFAULT_TITLE_FONT_SIZE = @17;
^

Affected File:
node_modules/react-native-screens/ios/RNSScreenStackHeaderConfig.mm (lines 42-43)
Why Standard Reproduction Differs:
This is a C++ compiler error during native build compilation
Occurs only with Xcode 26.2's stricter C++ compliance enforcement
100% deterministic - all Xcode 26.2 users will hit this
Cannot be shown in runtime or Snack environments
If reviewer doesn't have Xcode 26.2, they cannot see the error
Verification:
Any existing React Native 0.76+ project with react-native-screens 4.17.0-4.18.0 will fail to build on Xcode 26.2.

Snack or a link to a repository

https://gist.github.com/awais-wego/1edc8258a417e67880d94e137a87141d

Screens version

4.18.0

React Native version

0.77.0

Platforms

iOS

JavaScript runtime

None

Workflow

React Native (without Expo)

Architecture

Fabric (New Architecture)

Build type

Release mode

Device

None

Device model

No response

Acknowledgements

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Platform: iOSThis issue is specific to iOSRepro providedA reproduction with a snack or repo is provided

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions