mirror of
https://github.com/openharmony/ace_ace_engine.git
synced 2026-07-21 01:45:30 -04:00
add rotationvibrate attribute
Signed-off-by: wzzwhuhku <wzzwhuhku@163.com> Change-Id: Id76fb9d16749fcee0c2385b23f6c28d4d9ff6a23
This commit is contained in:
@@ -118,6 +118,10 @@ bool DOMList::SetSpecializedAttr(const std::pair<std::string, std::string>& attr
|
||||
LIST_REPEATED_LENGTH,
|
||||
[](DOMList& list, const std::string& val) { list.repeatedLength_ = StringUtils::StringToInt(val); },
|
||||
},
|
||||
{
|
||||
DOM_LIST_ROTATION_VIBRATE,
|
||||
[](DOMList& list, const std::string& val) { list.rotationVibrate_ = StringToBool(val); },
|
||||
},
|
||||
{
|
||||
DOM_SCROLL_SCROLLBAR,
|
||||
[](DOMList& list, const std::string& val) {
|
||||
@@ -309,6 +313,7 @@ void DOMList::CreateOrUpdateList()
|
||||
}
|
||||
|
||||
listComponent_->SetScrollVibrate(scrollVibrate_);
|
||||
listComponent_->MarkNeedRotationVibrate(rotationVibrate_);
|
||||
|
||||
listComponent_->SetDirection(flexDirection_);
|
||||
if (flexDirection_ == FlexDirection::COLUMN || flexDirection_ == FlexDirection::COLUMN_REVERSE) {
|
||||
|
||||
@@ -66,6 +66,11 @@ public:
|
||||
return scrollVibrate_;
|
||||
}
|
||||
|
||||
bool NeedRotationVibrate() const
|
||||
{
|
||||
return rotationVibrate_;
|
||||
}
|
||||
|
||||
bool GetItemCenter() const
|
||||
{
|
||||
return itemCenter_;
|
||||
@@ -152,6 +157,7 @@ private:
|
||||
bool itemCenter_ = false;
|
||||
bool centerLayout_ = false;
|
||||
bool scrollVibrate_ = true;
|
||||
bool rotationVibrate_ = false;
|
||||
bool scrollPage_ = false;
|
||||
bool chainAnimation_ = false;
|
||||
SpringChainProperty chainProperty_;
|
||||
|
||||
@@ -290,7 +290,10 @@ void DOMListItem::OnMounted(const RefPtr<DOMNode>& parentNode)
|
||||
if (listItemComponent_ && parentNodeTmp) {
|
||||
listItemComponent_->SetSupportScale(parentNodeTmp->GetItemScale());
|
||||
listItemComponent_->SetSupportOpacity(parentNodeTmp->GetItemOpacity());
|
||||
// NeedVibrate means scroll and rotation all trigger vibrate.
|
||||
// RotationVibrate means only rotation trigger vibrate.
|
||||
listItemComponent_->MarkNeedVibrate(parentNodeTmp->NeedVibrate());
|
||||
listItemComponent_->MarkNeedRotationVibrate(parentNodeTmp->NeedRotationVibrate());
|
||||
SetDividerStyle(parentNode);
|
||||
}
|
||||
} else if (parentNode->GetTag() == DOM_NODE_TAG_LIST_ITEM_GROUP) {
|
||||
|
||||
@@ -471,6 +471,7 @@ const char DOM_LIST_ITEM_OPACITY[] = "itemopacity";
|
||||
const char DOM_LIST_ITEM_CENTER[] = "itemcenter";
|
||||
const char DOM_LIST_CENTER_LAYOUT[] = "centerlayout";
|
||||
const char DOM_LIST_SCROLL_VIBRATE[] = "scrollvibrate";
|
||||
const char DOM_LIST_ROTATION_VIBRATE[] = "rotationvibrate";
|
||||
const char DOM_LIST_DIVIDER[] = "divider";
|
||||
const char DOM_LIST_DIVIDER_COLOR[] = "dividerColor";
|
||||
const char DOM_LIST_DIVIDER_HEIGHT[] = "dividerHeight";
|
||||
|
||||
@@ -471,6 +471,7 @@ ACE_EXPORT extern const char DOM_LIST_ITEM_OPACITY[];
|
||||
ACE_EXPORT extern const char DOM_LIST_ITEM_CENTER[];
|
||||
ACE_EXPORT extern const char DOM_LIST_CENTER_LAYOUT[];
|
||||
ACE_EXPORT extern const char DOM_LIST_SCROLL_VIBRATE[];
|
||||
ACE_EXPORT extern const char DOM_LIST_ROTATION_VIBRATE[];
|
||||
ACE_EXPORT extern const char DOM_LIST_DIVIDER[];
|
||||
ACE_EXPORT extern const char DOM_LIST_DIVIDER_COLOR[];
|
||||
ACE_EXPORT extern const char DOM_LIST_DIVIDER_HEIGHT[];
|
||||
|
||||
@@ -515,6 +515,16 @@ public:
|
||||
return scrollVibrate_;
|
||||
}
|
||||
|
||||
bool IsRotationVibrate() const
|
||||
{
|
||||
return rotationVibrate_;
|
||||
}
|
||||
|
||||
void MarkNeedRotationVibrate(bool needVibrate)
|
||||
{
|
||||
rotationVibrate_ = needVibrate;
|
||||
}
|
||||
|
||||
private:
|
||||
EventMarker onRequestItem_;
|
||||
EventMarker onScroll_;
|
||||
@@ -565,6 +575,7 @@ private:
|
||||
bool needDivider_ = false;
|
||||
|
||||
bool scrollVibrate_ = true;
|
||||
bool rotationVibrate_ = false;
|
||||
};
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
@@ -250,6 +250,16 @@ public:
|
||||
needVibrate_ = needVibrate;
|
||||
}
|
||||
|
||||
bool IsRotationVibrate() const
|
||||
{
|
||||
return rotationVibrate_;
|
||||
}
|
||||
|
||||
void MarkNeedRotationVibrate(bool needVibrate)
|
||||
{
|
||||
rotationVibrate_ = needVibrate;
|
||||
}
|
||||
|
||||
bool IsTitle() const
|
||||
{
|
||||
return isTitle_;
|
||||
@@ -425,6 +435,7 @@ private:
|
||||
std::string indexKey_;
|
||||
std::string key_;
|
||||
bool needVibrate_ = true;
|
||||
bool rotationVibrate_ = false;
|
||||
bool supportScale_ = true;
|
||||
bool supportOpacity_ = false;
|
||||
bool supportClick_ = true;
|
||||
|
||||
@@ -137,6 +137,11 @@ void ListWatchLayoutManager::SetChildPosition(const RefPtr<RenderNode>& child, i
|
||||
|
||||
void ListWatchLayoutManager::HandleItemStateAndEffect()
|
||||
{
|
||||
auto isFromRotate = false;
|
||||
auto parentScroll = AceType::DynamicCast<RenderScroll>(renderList_.GetParent().Upgrade());
|
||||
if (parentScroll) {
|
||||
isFromRotate = parentScroll->IsFromRotate();
|
||||
}
|
||||
RefPtr<RenderListItem> listItem;
|
||||
for (const auto& item : renderList_.GetItems()) {
|
||||
if (!item.second || item.second->GetChildren().empty()) {
|
||||
@@ -153,7 +158,7 @@ void ListWatchLayoutManager::HandleItemStateAndEffect()
|
||||
(centerIndex == INVALID_INDEX && index == renderList_.GetCurrentMaxIndex())) {
|
||||
listItem->SetCurrentState(ItemState::NEARBY);
|
||||
}
|
||||
listItem->HandleItemEffect();
|
||||
listItem->HandleItemEffect(isFromRotate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -195,6 +195,11 @@ void RenderListItem::Update(const RefPtr<Component>& component)
|
||||
vibrator_ = VibratorProxy::GetInstance().GetVibrator(context->GetTaskExecutor());
|
||||
}
|
||||
|
||||
rotationVibrate_ = item->IsRotationVibrate();
|
||||
if (rotationVibrate_ && !vibrator_ && context) {
|
||||
vibrator_ = VibratorProxy::GetInstance().GetVibrator(context->GetTaskExecutor());
|
||||
}
|
||||
|
||||
supportScale_ = item->GetSupportScale();
|
||||
supportOpacity_ = item->GetSupportOpacity();
|
||||
supportClick_ = item->GetSupportClick();
|
||||
@@ -299,7 +304,7 @@ void RenderListItem::ResetFocusEffect()
|
||||
}
|
||||
}
|
||||
|
||||
void RenderListItem::HandleItemEffect()
|
||||
void RenderListItem::HandleItemEffect(bool isFromRotate)
|
||||
{
|
||||
if (!focusController_) {
|
||||
ResetFocusEffect();
|
||||
@@ -310,6 +315,9 @@ void RenderListItem::HandleItemEffect()
|
||||
if (needVibrate_ && lastState_ == ItemState::NEARBY && currentState_ == ItemState::FOCUS && vibrator_) {
|
||||
vibrator_->Vibrate(VIBRATOR_TYPE_WATCH_CROWN_STRENGTH1);
|
||||
}
|
||||
if (rotationVibrate_ && isFromRotate) {
|
||||
vibrator_->Vibrate(VIBRATOR_TYPE_WATCH_CROWN_STRENGTH1);
|
||||
}
|
||||
#endif
|
||||
LOGD("item (%{public}d) change from %{public}d to %{public}d.", index_, lastState_, currentState_);
|
||||
lastState_ = currentState_;
|
||||
|
||||
@@ -211,7 +211,7 @@ public:
|
||||
redraw_ = redraw;
|
||||
}
|
||||
|
||||
void HandleItemEffect();
|
||||
void HandleItemEffect(bool isFromRotate = false);
|
||||
|
||||
// judge is item at center of viewport or not, used on watch
|
||||
bool IsItemCenter(bool isVertical, Size viewport);
|
||||
@@ -345,6 +345,7 @@ protected:
|
||||
RefPtr<InteractiveEffect> focusController_;
|
||||
RefPtr<RenderDisplay> renderDisplay_;
|
||||
bool needVibrate_ = true;
|
||||
bool rotationVibrate_ = false;
|
||||
bool supportScale_ = true;
|
||||
bool supportOpacity_ = false;
|
||||
bool supportClick_ = true;
|
||||
|
||||
@@ -235,6 +235,11 @@ void RenderMultiChildScroll::Update(const RefPtr<Component>& component)
|
||||
vibrator_ = VibratorProxy::GetInstance().GetVibrator(context->GetTaskExecutor());
|
||||
}
|
||||
|
||||
rotationVibrate_ = listComponent->IsRotationVibrate();
|
||||
if (rotationVibrate_ && !vibrator_ && context) {
|
||||
vibrator_ = VibratorProxy::GetInstance().GetVibrator(context->GetTaskExecutor());
|
||||
}
|
||||
|
||||
if (listComponent->IsInRefresh()) {
|
||||
auto parent = GetParent().Upgrade();
|
||||
while (parent) {
|
||||
@@ -520,6 +525,9 @@ bool RenderMultiChildScroll::HandleCrashTop()
|
||||
if (scrollVibrate_ && vibrator_) {
|
||||
vibrator_->Vibrate(VIBRATOR_TYPE_WATCH_CROWN_STRENGTH3);
|
||||
}
|
||||
if (rotationVibrate_ && IsFromRotate()) {
|
||||
vibrator_->Vibrate(VIBRATOR_TYPE_WATCH_CROWN_STRENGTH3);
|
||||
}
|
||||
#endif
|
||||
return RenderScroll::HandleCrashTop();
|
||||
}
|
||||
@@ -529,6 +537,9 @@ bool RenderMultiChildScroll::HandleCrashBottom()
|
||||
if (scrollVibrate_ && vibrator_) {
|
||||
vibrator_->Vibrate(VIBRATOR_TYPE_WATCH_CROWN_STRENGTH3);
|
||||
}
|
||||
if (rotationVibrate_ && IsFromRotate()) {
|
||||
vibrator_->Vibrate(VIBRATOR_TYPE_WATCH_CROWN_STRENGTH3);
|
||||
}
|
||||
#endif
|
||||
return RenderScroll::HandleCrashBottom();
|
||||
}
|
||||
|
||||
@@ -128,6 +128,7 @@ private:
|
||||
double effectOffset_ = 0.0;
|
||||
double accumulatedRotationValue_ = 0.0;
|
||||
bool scrollVibrate_ = true;
|
||||
bool rotationVibrate_ = false;
|
||||
|
||||
RefPtr<Animator> animateController_;
|
||||
RefPtr<Vibrator> vibrator_;
|
||||
|
||||
@@ -162,6 +162,11 @@ bool RenderScroll::HandleCrashTop()
|
||||
|
||||
bool RenderScroll::UpdateOffset(Offset& delta, int32_t source)
|
||||
{
|
||||
if (source == SCROLL_FROM_ROTATE) {
|
||||
isFromRotate_ = true;
|
||||
} else {
|
||||
isFromRotate_ = false;
|
||||
}
|
||||
if (!scrollable_->Available()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -195,6 +195,16 @@ public:
|
||||
virtual bool HandleCrashTop();
|
||||
virtual bool HandleCrashBottom();
|
||||
|
||||
void SetIsFromRotate(bool isRotate)
|
||||
{
|
||||
isFromRotate_ = isRotate;
|
||||
}
|
||||
|
||||
bool IsFromRotate()
|
||||
{
|
||||
return isFromRotate_;
|
||||
}
|
||||
|
||||
protected:
|
||||
explicit RenderScroll();
|
||||
|
||||
@@ -221,6 +231,7 @@ protected:
|
||||
double estimatedHeight_ = 0.0;
|
||||
double moveDistance_ = 0.0;
|
||||
bool scrollPage_ = false;
|
||||
bool isFromRotate_ = false;
|
||||
RefPtr<ScrollPositionController> positionController_;
|
||||
RefPtr<ScrollEdgeEffect> scrollEffect_;
|
||||
RefPtr<Scrollable> scrollable_;
|
||||
|
||||
Reference in New Issue
Block a user