• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/base/i18n/time_format.h"
25 #include "frameworks/bridge/declarative_frontend/jsview/dialog/js_alert_dialog.h"
26 #include "bridge/declarative_frontend/ark_theme/theme_apply/js_theme_utils.h"
27 #include "core/components_ng/pattern/picker/picker_model.h"
28 
29 namespace OHOS::Ace::Framework {
30 class JSDatePicker : public JSViewAbstract {
31 public:
32     static void Create(const JSCallbackInfo& info);
33 
34     static void JSBind(BindingTarget globalObj);
35     static void SetLunar(bool isLunar);
36     static void OnChange(const JSCallbackInfo& info);
37     static void OnDateChange(const JSCallbackInfo& info);
38     static void PickerBackgroundColor(const JSCallbackInfo& info);
39     static void SetDisappearTextStyle(const JSCallbackInfo& info);
40     static void SetTextStyle(const JSCallbackInfo& info);
41     static void SetSelectedTextStyle(const JSCallbackInfo& info);
42     static void ParseTextStyle(const JSRef<JSObject>& paramObj, NG::PickerTextStyle& textStyle, const std::string& pos);
43     static void ParseTextProperties(const JSRef<JSObject>& paramObj, NG::PickerTextProperties& result);
44     // keep compatible, need remove after
45     static void UseMilitaryTime(bool isUseMilitaryTime);
46     static void IsUserDefinedFontFamily(const std::string& pos);
47     static void JsOpacity(const JSCallbackInfo& info);
48 
49 private:
50     static void CreateDatePicker(const JSCallbackInfo& info, const JSRef<JSObject>& paramObj);
51     // keep compatible, need remove after
52     static void CreateTimePicker(const JSCallbackInfo& info, const JSRef<JSObject>& paramObj);
53     static PickerDate ParseDate(const JSRef<JSVal>& dateVal);
54     static void SetDefaultAttributes();
55     // keep compatible, need remove after
56     static PickerTime ParseTime(const JSRef<JSVal>& timeVal);
57 };
58 
59 class JSDatePickerDialog : JSAlertDialog {
60 public:
61     static void JSBind(BindingTarget globalObj);
62     static void Show(const JSCallbackInfo& info);
63     static void DatePickerDialogShow(const JSRef<JSObject>& paramObj,
64         const std::map<std::string, NG::DialogEvent>& dialogEvent,
65         const std::map<std::string, NG::DialogGestureEvent>& dialogCancelEvent);
66     static void ParseDateTimeOptions(const JSRef<JSObject>& paramObj, DateTimeType& dateTimeOptions);
67     static JsiRef<JsiValue> GetDateObj(const std::unique_ptr<JsonValue>& selectedJson, bool isDatePicker = true);
68 
69 private:
70     static std::function<void(const std::string&)> GetDateChangeEvent(const JSRef<JSObject>& paramObject,
71         const JSCallbackInfo& info, const DatePickerType& pickerType, const WeakPtr<NG::FrameNode>& frameNode);
72     static std::function<void(const std::string&)> GetDateAcceptEvent(const JSRef<JSObject>& paramObject,
73         const JSCallbackInfo& info, const DatePickerType& pickerType, const WeakPtr<NG::FrameNode>& frameNode);
74     static std::function<void(const std::string&)> GetChangeEvent(const JSRef<JSObject>& paramObject,
75         const JSCallbackInfo& info, const DatePickerType& pickerType, const WeakPtr<NG::FrameNode>& frameNode);
76     static std::function<void(const std::string&)> GetAcceptEvent(
77         const JSRef<JSObject>& paramObject, const JSCallbackInfo& info, const WeakPtr<NG::FrameNode>& frameNode);
78     static std::function<void()> GetCancelEvent(
79         const JSRef<JSObject>& paramObject, const JSCallbackInfo& info, const WeakPtr<NG::FrameNode>& frameNode);
80     static void UpdateDatePickerSettingData(const JSRef<JSObject>& paramObject, NG::DatePickerSettingData& settingData);
81     static void UpdatePickerDialogTimeInfo(const JSRef<JSObject>& paramObject, PickerDialogInfo& pickerDialog);
82     static void UpdatePickerDialogPositionInfo(const JSRef<JSObject>& paramObject, PickerDialogInfo& pickerDialog);
83     static void UpdatePickerDialogInfo(const JSRef<JSObject>& paramObject, PickerDialogInfo& pickerDialog);
84 
85     static void CreateDatePicker(RefPtr<Component>& component, const JSRef<JSObject>& paramObj);
86     // keep compatible, need remove after
87     static void CreateTimePicker(RefPtr<Component>& component, const JSRef<JSObject>& paramObj);
88     static PickerDate ParseDate(const JSRef<JSVal>& dateVal);
89     // keep compatible, need remove after
90     static PickerTime ParseTime(const JSRef<JSVal>& timeVal);
91 };
92 
93 class JSTimePicker : public JSViewAbstract {
94 public:
95     static void Create(const JSCallbackInfo& info);
96 
97     static void JSBind(BindingTarget globalObj);
98     static void OnChange(const JSCallbackInfo& info);
99     static void Loop(const JSCallbackInfo& info);
100     static void UseMilitaryTime(bool isUseMilitaryTime);
101     static void EnableHapticFeedback(const JSCallbackInfo& info);
102     static void PickerBackgroundColor(const JSCallbackInfo& info);
103 
104     static void SetDisappearTextStyle(const JSCallbackInfo& info);
105     static void SetTextStyle(const JSCallbackInfo& info);
106     static void SetSelectedTextStyle(const JSCallbackInfo& info);
107     static void DateTimeOptions(const JSCallbackInfo& info);
108     static void JsOpacity(const JSCallbackInfo& info);
109 
110 private:
111     static void CreateTimePicker(const JSCallbackInfo& info, const JSRef<JSObject>& paramObj);
112     static void SetDefaultAttributes();
113     static PickerTime ParseTime(const JSRef<JSVal>& timeVal);
114 };
115 
116 class JSTimePickerDialog {
117 public:
118     static void JSBind(BindingTarget globalObj);
119     static void Show(const JSCallbackInfo& info);
120     static void TimePickerDialogShow(const JSRef<JSObject>& paramObj,
121         const std::map<std::string, NG::DialogEvent>& dialogEvent,
122         const std::map<std::string, NG::DialogGestureEvent>& dialogCancelEvent);
123 
124 private:
125     static void CreateTimePicker(RefPtr<Component>& component, const JSRef<JSObject>& paramObj);
126     static PickerTime ParseTime(const JSRef<JSVal>& timeVal);
127     static PickerDate ParseDate(const JSRef<JSVal>& dateVal);
128 };
129 } // namespace OHOS::Ace::Framework
130 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_DATEPICKER_H
131