1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_DATEPICKER_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_DATEPICKER_H 18 19 #include "bridge/declarative_frontend/jsview/js_interactable_view.h" 20 #include "bridge/declarative_frontend/jsview/js_view_abstract.h" 21 #include "core/components/picker/picker_base_component.h" 22 #include "core/components_ng/pattern/picker/datepicker_event_hub.h" 23 #include "core/components_ng/pattern/picker/picker_type_define.h" 24 #include "frameworks/bridge/declarative_frontend/jsview/dialog/js_alert_dialog.h" 25 26 namespace OHOS::Ace::Framework { 27 class JSDatePicker : public JSViewAbstract { 28 public: 29 static void Create(const JSCallbackInfo& info); 30 31 static void JSBind(BindingTarget globalObj); 32 static void SetLunar(bool isLunar); 33 static void OnChange(const JSCallbackInfo& info); 34 static void OnDateChange(const JSCallbackInfo& info); 35 static void PickerBackgroundColor(const JSCallbackInfo& info); 36 static void SetDisappearTextStyle(const JSCallbackInfo& info); 37 static void SetTextStyle(const JSCallbackInfo& info); 38 static void SetSelectedTextStyle(const JSCallbackInfo& info); 39 static void ParseTextStyle(const JSRef<JSObject>& paramObj, NG::PickerTextStyle& textStyle); 40 static void ParseTextProperties(const JSRef<JSObject>& paramObj, NG::PickerTextProperties& result); 41 // keep compatible, need remove after 42 static void UseMilitaryTime(bool isUseMilitaryTime); 43 44 private: 45 static void CreateDatePicker(const JSCallbackInfo& info, const JSRef<JSObject>& paramObj); 46 // keep compatible, need remove after 47 static void CreateTimePicker(const JSCallbackInfo& info, const JSRef<JSObject>& paramObj); 48 static PickerDate ParseDate(const JSRef<JSVal>& dateVal); 49 static void SetDefaultAttributes(); 50 // keep compatible, need remove after 51 static PickerTime ParseTime(const JSRef<JSVal>& timeVal); 52 }; 53 54 class JSDatePickerDialog : JSAlertDialog { 55 public: 56 static void JSBind(BindingTarget globalObj); 57 static void Show(const JSCallbackInfo& info); 58 static void DatePickerDialogShow(const JSRef<JSObject>& paramObj, 59 const std::map<std::string, NG::DialogEvent>& dialogEvent, 60 const std::map<std::string, NG::DialogGestureEvent>& dialogCancelEvent); 61 62 private: 63 static void CreateDatePicker(RefPtr<Component>& component, const JSRef<JSObject>& paramObj); 64 // keep compatible, need remove after 65 static void CreateTimePicker(RefPtr<Component>& component, const JSRef<JSObject>& paramObj); 66 static PickerDate ParseDate(const JSRef<JSVal>& dateVal); 67 // keep compatible, need remove after 68 static PickerTime ParseTime(const JSRef<JSVal>& timeVal); 69 }; 70 71 class JSTimePicker : public JSViewAbstract { 72 public: 73 static void Create(const JSCallbackInfo& info); 74 75 static void JSBind(BindingTarget globalObj); 76 static void OnChange(const JSCallbackInfo& info); 77 static void Loop(bool isLoop); 78 static void UseMilitaryTime(bool isUseMilitaryTime); 79 static void PickerBackgroundColor(const JSCallbackInfo& info); 80 81 static void SetDisappearTextStyle(const JSCallbackInfo& info); 82 static void SetTextStyle(const JSCallbackInfo& info); 83 static void SetSelectedTextStyle(const JSCallbackInfo& info); 84 85 private: 86 static void CreateTimePicker(const JSCallbackInfo& info, const JSRef<JSObject>& paramObj); 87 static void SetDefaultAttributes(); 88 static PickerTime ParseTime(const JSRef<JSVal>& timeVal); 89 }; 90 91 class JSTimePickerDialog { 92 public: 93 static void JSBind(BindingTarget globalObj); 94 static void Show(const JSCallbackInfo& info); 95 static void TimePickerDialogShow(const JSRef<JSObject>& paramObj, 96 const std::map<std::string, NG::DialogEvent>& dialogEvent, 97 const std::map<std::string, NG::DialogGestureEvent>& dialogCancelEvent); 98 99 private: 100 static void CreateTimePicker(RefPtr<Component>& component, const JSRef<JSObject>& paramObj); 101 static PickerTime ParseTime(const JSRef<JSVal>& timeVal); 102 static PickerDate ParseDate(const JSRef<JSVal>& dateVal); 103 }; 104 } // namespace OHOS::Ace::Framework 105 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_DATEPICKER_H 106