!219 修改显隐软键盘接口返回值

Merge pull request !219 from 赵凌岚/master
This commit is contained in:
openharmony_ci 2022-08-16 06:39:33 +00:00 committed by Gitee
commit 7765504e8e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 22 additions and 22 deletions

View File

@ -122,43 +122,35 @@ declare namespace inputMethod {
* Show soft keyboard
* @since 9
* @param callback
* @return :
* if true, success.
* if false, fail.
* @return : -
* @syscap SystemCapability.MiscServices.InputMethodFramework
*/
showSoftKeyboard(callback: AsyncCallback<boolean>): void;
showSoftKeyboard(callback: AsyncCallback<void>): void;
/**
* Show soft keyboard
* @since 9
* @return :
* if true, success.
* if false, fail.
* @return : -
* @syscap SystemCapability.MiscServices.InputMethodFramework
*/
showSoftKeyboard():Promise<boolean>;
showSoftKeyboard():Promise<void>;
/**
* Hide soft keyboard
* @since 9
* @param callback
* @return :
* if true, success.
* if false, fail.
* @return : -
* @syscap SystemCapability.MiscServices.InputMethodFramework
*/
hideSoftKeyboard(callback: AsyncCallback<boolean>): void;
hideSoftKeyboard(callback: AsyncCallback<void>): void;
/**
* Hide soft keyboard
* @since 9
* @return :
* if true, success.
* if false, fail.
* @return : -
* @syscap SystemCapability.MiscServices.InputMethodFramework
*/
hideSoftKeyboard():Promise<boolean>;
hideSoftKeyboard():Promise<void>;
}
/**

View File

@ -84,7 +84,7 @@ napi_value JsGetInputMethodController::GetInputMethodController(napi_env env, na
}
napi_value JsGetInputMethodController::HandleSoftKeyboard(
napi_env env, napi_callback_info info, std::function<int32_t()> callback)
napi_env env, napi_callback_info info, std::function<int32_t()> callback, bool isOutput)
{
auto ctxt = std::make_shared<HandleContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
@ -105,24 +105,31 @@ napi_value JsGetInputMethodController::HandleSoftKeyboard(
ctxt->isHandle = true;
}
};
ctxt->SetAction(std::move(input), std::move(output));
if (isOutput) {
ctxt->SetAction(std::move(input), std::move(output));
} else {
ctxt->SetAction(std::move(input));
}
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(ctxt), 0);
return asyncCall.Call(env, exec);
}
napi_value JsGetInputMethodController::ShowSoftKeyboard(napi_env env, napi_callback_info info)
{
return HandleSoftKeyboard(env, info, [] { return InputMethodController::GetInstance()->ShowCurrentInput(); });
return HandleSoftKeyboard(
env, info, [] { return InputMethodController::GetInstance()->ShowCurrentInput(); }, false);
}
napi_value JsGetInputMethodController::HideSoftKeyboard(napi_env env, napi_callback_info info)
{
return HandleSoftKeyboard(env, info, [] { return InputMethodController::GetInstance()->HideCurrentInput(); });
return HandleSoftKeyboard(
env, info, [] { return InputMethodController::GetInstance()->HideCurrentInput(); }, false);
}
napi_value JsGetInputMethodController::StopInput(napi_env env, napi_callback_info info)
{
return HandleSoftKeyboard(env, info, [] { return InputMethodController::GetInstance()->HideCurrentInput(); });
return HandleSoftKeyboard(
env, info, [] { return InputMethodController::GetInstance()->HideCurrentInput(); }, true);
}
} // namespace MiscServices
} // namespace OHOS

View File

@ -47,7 +47,8 @@ public:
~JsGetInputMethodController() = default;
static napi_value Init(napi_env env, napi_value info);
static napi_value GetInputMethodController(napi_env env, napi_callback_info info);
static napi_value HandleSoftKeyboard(napi_env env, napi_callback_info info, std::function<int32_t()> callback);
static napi_value HandleSoftKeyboard(
napi_env env, napi_callback_info info, std::function<int32_t()> callback, bool isOutput);
static napi_value HideSoftKeyboard(napi_env env, napi_callback_info info);
static napi_value ShowSoftKeyboard(napi_env env, napi_callback_info info);
static napi_value StopInput(napi_env env, napi_callback_info info);