Collection TextField and Keyboard

Hi,

I'm using a TTMSFMXNativeUICollectionViewTemplateTextField when editing on an iPad the keyboard hide/collapse button works as expected but on an iPhone the Done button doesn't do anything.

Ken

the done button is added programmatically in the FireMonkey framework which hooks onto the virtual keyboard. (FMX.VirtualKeyboard.iOS.pas) this hooking only works for FireMonkey controls.


     if not Assigned(FHideButton) then
      begin
        FHideButton := TUIBarButtonItem.Create;
        FHideButton.setTitle(StrToNSStr(SEditorDone));
        FHideButton.setStyle(UIBarButtonItemStyleDone);
        FHideButton.setTarget(FKeyboardHandler.GetObjectID);
        FHideButton.setAction(sel_getUid('HideVirtualKeyboard'));
      end;

procedure TKeyboardEventHandler.HideVirtualKeyboard;
begin
  try
    Screen.ActiveForm.Focused := nil;
  except
    Application.HandleException(Screen.ActiveForm);
  end;
end;

It's unclear how this could be solved on our side, because the hooking shouldn't be necessary when using native controls.

Kind Regards, 
Pieter

Pieter Scheldeman2015-02-27 10:30:46

Thanks for the info but doesn't really help :)

How come it works on an iPad but not an iPhone?

This was just for clarification that it's the code from the FireMonkey source that interferes with this process.

on iPad, the done button isn't created and thus it doesn't interferes with the virtual keyboard. the virtual keyboard is different, and has an additional button to close the keyboard. It could be possible that you will have to set the focus to a FireMonkey control when starting the editing on the native UITextView control. The OnItemTextViewDidBeginEditing event could be used for this.

Kind Regards, 
Pieter

Pieter,

Users should surely expect something so fundamental on the keyboard as the Done button to work.

Ken

Dear Ken, 


The done button is something that is added hardcoded by the FireMonkey framework. As FireMonkey interferes with this process to support FireMonkey controls there is no way to intercept this event, or hide the done button. We will further investigate this here but please understand that is a technical issue that we'll have to overcome.

Kind Regards, 
Pieter

Thanks, understood and appreciated but until resolved it makes these controls unusable for editing.

Ken

Can you please let me know if you are likely to be able to resolve this?

Ken

Is there an update on this as iCL is unusable without this being remedied!

Hi, 


Please note that the default virtual keyboard on iOS 7/8 for iPhone does not contain a done key. The done button as explained in the previous posts is added by Embarcadero which intercepts the virtual keyboard handling, but there is no way to intercept this from a native control.

The only workaround to hide the keyboard is to change the return key type directly on the native control which will change the return key to a done key and clicking it will hide the keyboard.

procedure TForm1.TMSFMXNativeUICollectionView1AddItemControl(Sender: TObject;
  AControl: TTMSFMXNativeUICollectionViewTemplateControl);
begin
  AsTextField(AControl).TextField.setReturnKeyType(UIReturnKeyDone);
end;

Kind Regards, 
Pieter

I found this thread because I had the same problem. I have solved with the procedure below, which hides this default FMX toolbar on the keyboard. Now I can create my own toolbar to the keyboard (simply use the iCL UIToolbar implementation) and assign it to the keyboard for a textfield using this line:

    MyTMSNativeUITextField.TextField.setInputAccessoryView(MyTMSNativeUIToolBar.ToolBar);

procedure HideFMXKeyboardToolbar;
var
  lToolbarService: IFMXVirtualKeyboardToolbarService;
begin
  TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardToolbarService, IInterface(lToolbarService));
  if lToolbarService<>nil then
    lToolbarService.SetToolbarEnabled(False);
end;

Thanks Hans for the input!

You are welcome. I actually have a supplement for this, because I had big problems hiding the keyboard again. The normal way using Objective-C would be to call:

    MyTMSNativeUITextField.TextField.endEditing(true)

However, this only hides the custom toolbar of the keyboard (which indicates that the textfield actually stopped editing), but the keyboard remains open.
After hours of experimenting and testing, I found a way. Simply call this function after the EndEditing function above:

procedure HideNativeKeyboard;
var lKeyWindow: UIWindow;
begin
  lKeyWindow := SharedApplication.keyWindow;
  if lKeyWindow<>nil then
  begin
    if lKeyWindow.rootViewController <> nil then
      lKeyWindow.rootViewController.view.endEditing(true);
    lKeyWindow.endEditing(true);
  end;
end;