Skip to content

Conversation

snobiwe
Copy link

@snobiwe snobiwe commented Oct 14, 2025

📜 Description

There's a critical type mismatch in the iOS implementation of setAffinityCalculationStrategy method that causes crashes when the affinity calculation strategy is set. The method signature in the header file declares the parameter as NSNumber * but the implementation was trying to pass an NSInteger value directly, causing a type mismatch and potential runtime crashes.

💡 Motivation and Context

This change is required to fix a critical bug in the iOS implementation where setting the affinityCalculationStrategy prop would cause the app to crash due to a type mismatch between the method signature and the actual parameter being passed. The issue occurs when React Native tries to call the native method with an integer value, but the method expects an NSNumber object.

There is a closed issue about that but that was fixed only for old architecture
My fix is for a new one

#97

📢 Changelog

iOS

Fixed type mismatch in setAffinityCalculationStrategy method signature
Updated method call to properly wrap integer value with @() to convert to NSNumber
Resolved potential crash when setting affinity calculation strategy

🤔 How Has This Been Tested?

The fix has been tested by:
Verifying that the method signature in the header file matches the expected parameter type (NSNumber *)
Ensuring the implementation properly converts the integer value to NSNumber using the @() syntax
Confirming that the type mismatch error is resolved and the method can be called without crashes

📸 Screenshots (if appropriate):

Снимок экрана 2025-10-14 в 13 47 02

This is stacktrace for the crash

How to reproduce

Build an app with the lib with new architecture enabled
If prop affinityCalculationStrategy set, app crashes

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

@IvanIhnatsiuk
Copy link
Owner

@snobiwe Could you please provide additional details about the crash, including the steps to reproduce it?

@snobiwe
Copy link
Author

snobiwe commented Oct 14, 2025

@IvanIhnatsiuk i've updated the comment to my pr with stacktrace

@snobiwe
Copy link
Author

snobiwe commented Oct 14, 2025

For testing we've built an app with this prop commented (affinityCalculationStrategy prop) and everything worked properly
If this prop uncommented app stacks with stacktrace i provided in description

We fixed this locally with the patch

diff --git a/ios/AdvancedTextInputViewContainer.h b/ios/AdvancedTextInputViewContainer.h
index 3b55fb22aacf6350c9b8b42e4aad1978ae2a3b8d..a3a8539c9ce74e612dbebbb90f9a9e7866f65506 100644
--- a/ios/AdvancedTextInputViewContainer.h
+++ b/ios/AdvancedTextInputViewContainer.h
@@ -29,7 +29,7 @@
 - (void)setDefaultValue:(NSString *)defaultValue;
 - (void)setValue:(NSString *)value;
 - (void)setAffinityFormat:(NSArray<NSString *> *)affinityFormat;
-- (void)setAffinityCalculationStrategy:(NSInteger)affinityCalculationStrategy;
+- (void)setAffinityCalculationStrategy:(NSNumber *)affinityCalculationStrategy;
 - (void)setValidationRegex:(NSString *)validationRegex;
 - (void)cleanup;
 - (void)setMaskedText:(NSString *_Nonnull)text autocomplete:(BOOL)autocomplete;
diff --git a/ios/AdvancedtextInputMaskDecoratorView.mm b/ios/AdvancedtextInputMaskDecoratorView.mm
index b22204f31fe0dd6c46c3f040fc35f424f70de922..95f85b32036751c435b269efed56a8c337913a1e 100644
--- a/ios/AdvancedtextInputMaskDecoratorView.mm
+++ b/ios/AdvancedtextInputMaskDecoratorView.mm
@@ -121,7 +121,7 @@ - (void)updateProps:(const facebook::react::Props::Shared &)props
   }

   if (newViewProps.affinityCalculationStrategy != oldViewProps.affinityCalculationStrategy) {
-    [_view setAffinityCalculationStrategy:newViewProps.affinityCalculationStrategy];
+    [_view setAffinityCalculationStrategy:@(newViewProps.affinityCalculationStrategy)];
   }

   if (newViewProps.validationRegex != oldViewProps.validationRegex) {

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.

2 participants