Skip to content
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

iOS disable keyboard input for mode="time" #852

Open
enagorny opened this issue Dec 19, 2023 · 1 comment
Open

iOS disable keyboard input for mode="time" #852

enagorny opened this issue Dec 19, 2023 · 1 comment

Comments

@enagorny
Copy link

enagorny commented Dec 19, 2023

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @react-native-community/[email protected] for the project I'm working on.

This disables the keyboard input on the mode="time" which many of our users thought is a bug :-/ and this doesn't play well with the https://github.com/mmazzarolo/react-native-modal-datetime-picker

Here is the diff that solved my problem:

diff --git a/node_modules/@react-native-community/datetimepicker/ios/RNDateTimePicker.m b/node_modules/@react-native-community/datetimepicker/ios/RNDateTimePicker.m
index 9c73c8e..efaa23f 100644
--- a/node_modules/@react-native-community/datetimepicker/ios/RNDateTimePicker.m
+++ b/node_modules/@react-native-community/datetimepicker/ios/RNDateTimePicker.m
@@ -26,9 +26,9 @@
     #ifndef RCT_NEW_ARCH_ENABLED
       // somehow, with Fabric, the callbacks are executed here as well as in RNDateTimePickerComponentView
       // so do not register it with Fabric, to avoid potential problems
-      [self addTarget:self action:@selector(didChange)
-               forControlEvents:UIControlEventValueChanged];
+      [self addTarget:self action:@selector(didChange) forControlEvents:UIControlEventValueChanged];
       [self addTarget:self action:@selector(onDismiss:) forControlEvents:UIControlEventEditingDidEnd];
+      [self addTarget:self action:@selector(handleDatePickerTap) forControlEvents:UIControlEventEditingDidBegin];
     #endif
 
     _reactMinuteInterval = 1;
@@ -52,6 +52,11 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
   }
 }
 
+- (void)handleDatePickerTap
+{
+  [self resignFirstResponder];
+}
+
 - (void)setDatePickerMode:(UIDatePickerMode)datePickerMode
 {
   [super setDatePickerMode:datePickerMode];

This issue body was partially generated by patch-package.

@sen46Sko
Copy link

Hi friend.
I had the same problem. Thank you for your solution.

Could you tell, please, is it way to prevent time color changing on press on selected time?

image

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

No branches or pull requests

2 participants