NDK-CAPI: swiper margin support ignoreBlank

Signed-off-by: wangxinqiang007 <wangxinqiang2@huawei.com>
This commit is contained in:
wangxinqiang007 2024-05-29 17:05:15 +08:00
parent c2a5454be4
commit d7fb0cd2dc
10 changed files with 124 additions and 51 deletions

View File

@ -105,7 +105,8 @@ ArkUINativeModuleValue SwiperBridge::SetSwiperNextMargin(ArkUIRuntimeCallInfo* r
nextMargin.SetValue(0.0);
}
int32_t nextMarginUnit = static_cast<int32_t>(nextMargin.Unit());
GetArkUINodeModifiers()->getSwiperModifier()->setSwiperNextMargin(nativeNode, nextMargin.Value(), nextMarginUnit);
GetArkUINodeModifiers()->getSwiperModifier()->setSwiperNextMargin(
nativeNode, nextMargin.Value(), nextMarginUnit, 0);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue SwiperBridge::ResetSwiperNextMargin(ArkUIRuntimeCallInfo* runtimeCallInfo)
@ -131,7 +132,8 @@ ArkUINativeModuleValue SwiperBridge::SetSwiperPrevMargin(ArkUIRuntimeCallInfo* r
prevMargin.SetValue(0.0);
}
int32_t prevMarginUnit = static_cast<int32_t>(prevMargin.Unit());
GetArkUINodeModifiers()->getSwiperModifier()->setSwiperPrevMargin(nativeNode, prevMargin.Value(), prevMarginUnit);
GetArkUINodeModifiers()->getSwiperModifier()->setSwiperPrevMargin(
nativeNode, prevMargin.Value(), prevMarginUnit, 0);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue SwiperBridge::ResetSwiperPrevMargin(ArkUIRuntimeCallInfo* runtimeCallInfo)

View File

@ -83,6 +83,11 @@ struct AnimationCallbackInfo {
std::optional<float> velocity;
};
struct SwiperMarginOptions {
float margin;
bool ignoreBlank;
};
using AnimationStartEvent = std::function<void(int32_t index, int32_t targetIndex, const AnimationCallbackInfo& info)>;
using AnimationStartEventPtr = std::shared_ptr<AnimationStartEvent>;
using AnimationEndEvent = std::function<void(int32_t index, const AnimationCallbackInfo& info)>;

View File

@ -776,20 +776,26 @@ void SwiperModelNG::SetSwiperToIndex(FrameNode* frameNode, int32_t index, bool u
pattern->ChangeIndex(index, useAnimation);
}
float SwiperModelNG::GetPreviousMargin(FrameNode* frameNode, int32_t unit)
void SwiperModelNG::GetPreviousMargin(FrameNode* frameNode, int32_t unit, SwiperMarginOptions* options)
{
Dimension prevMargin(0.0f, static_cast<DimensionUnit>(unit));
ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
SwiperLayoutProperty, PrevMargin, prevMargin, frameNode, prevMargin);
return prevMargin.Value();
options->margin = prevMargin.Value();
auto pattern = frameNode->GetPattern<SwiperPattern>();
CHECK_NULL_VOID(pattern);
options->ignoreBlank = pattern->GetPrevMarginIgnoreBlank();
}
float SwiperModelNG::GetNextMargin(FrameNode* frameNode, int32_t unit)
void SwiperModelNG::GetNextMargin(FrameNode* frameNode, int32_t unit, SwiperMarginOptions* options)
{
Dimension nextMargin(0.0f, static_cast<DimensionUnit>(unit));
ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
SwiperLayoutProperty, NextMargin, nextMargin, frameNode, nextMargin);
return nextMargin.Value();
options->margin = nextMargin.Value();
auto pattern = frameNode->GetPattern<SwiperPattern>();
CHECK_NULL_VOID(pattern);
options->ignoreBlank = pattern->GetNextMarginIgnoreBlank();
}
std::shared_ptr<SwiperParameters> SwiperModelNG::GetDotIndicator(FrameNode* frameNode)

View File

@ -131,8 +131,8 @@ public:
static int32_t RealTotalCount(FrameNode* frameNode);
static void SetSwiperToIndex(FrameNode* frameNode, int32_t index, bool useAnimation);
static float GetPreviousMargin(FrameNode* frameNode, int32_t unit);
static float GetNextMargin(FrameNode* frameNode, int32_t unit);
static void GetPreviousMargin(FrameNode* frameNode, int32_t unit, SwiperMarginOptions* options);
static void GetNextMargin(FrameNode* frameNode, int32_t unit, SwiperMarginOptions* options);
static std::shared_ptr<SwiperParameters> GetDotIndicator(FrameNode* frameNode);
static int32_t GetIndicatorType(FrameNode* frameNode);
static RefPtr<SwiperController> GetSwiperController(FrameNode* frameNode);

View File

@ -672,6 +672,16 @@ public:
prevMarginIgnoreBlank_ = prevMarginIgnoreBlank;
}
bool GetPrevMarginIgnoreBlank()
{
return prevMarginIgnoreBlank_;
}
bool GetNextMarginIgnoreBlank()
{
return nextMarginIgnoreBlank_;
}
private:
void OnModifyDone() override;
void OnAfterModifyDone() override;

View File

@ -531,6 +531,11 @@ struct ArkUIScrollerAnimationType {
ArkUI_Int32 curve;
};
struct ArkUISwiperMarginOptions {
ArkUI_Float32 margin;
ArkUI_Bool ignoreBlank;
};
enum ArkUINodeType {
ARKUI_TEXT = 1,
ARKUI_SPAN,
@ -1933,9 +1938,11 @@ struct ArkUIParticleModifier {
};
struct ArkUISwiperModifier {
void (*setSwiperNextMargin)(ArkUINodeHandle node, ArkUI_Float32 nextMarginValue, ArkUI_Int32 nextMarginUnit);
void (*setSwiperNextMargin)(
ArkUINodeHandle node, ArkUI_Float32 nextMarginValue, ArkUI_Int32 nextMarginUnit, ArkUI_Bool ignoreBlank);
void (*resetSwiperNextMargin)(ArkUINodeHandle node);
void (*setSwiperPrevMargin)(ArkUINodeHandle node, ArkUI_Float32 prevMarginValue, ArkUI_Int32 prevMarginUnit);
void (*setSwiperPrevMargin)(
ArkUINodeHandle node, ArkUI_Float32 prevMarginValue, ArkUI_Int32 prevMarginUnit, ArkUI_Bool ignoreBlank);
void (*resetSwiperPrevMargin)(ArkUINodeHandle node);
void (*setSwiperDisplayCount)(ArkUINodeHandle node, ArkUI_CharPtr displayCountChar, ArkUI_CharPtr displayCountType);
void (*resetSwiperDisplayCount)(ArkUINodeHandle node);
@ -1992,8 +1999,8 @@ struct ArkUISwiperModifier {
void (*resetSwiperNestedScroll)(ArkUINodeHandle node);
ArkUI_Int32 (*getSwiperNestedScroll)(ArkUINodeHandle node);
void (*setSwiperToIndex)(ArkUINodeHandle node, ArkUI_Int32* values);
ArkUI_Float32 (*getSwiperPrevMargin)(ArkUINodeHandle node, ArkUI_Int32 unit);
ArkUI_Float32 (*getSwiperNextMargin)(ArkUINodeHandle node, ArkUI_Int32 unit);
void (*getSwiperPrevMargin)(ArkUINodeHandle node, ArkUI_Int32 unit, ArkUISwiperMarginOptions* options);
void (*getSwiperNextMargin)(ArkUINodeHandle node, ArkUI_Int32 unit, ArkUISwiperMarginOptions* options);
void (*setSwiperIndicatorStyle)(ArkUINodeHandle node, ArkUISwiperIndicator* swiperIndicator);
void (*getSwiperIndicator)(ArkUINodeHandle node, ArkUISwiperIndicator* swiperIndicator);
ArkUINodeHandle (*getSwiperController)(ArkUINodeHandle node);

View File

@ -404,11 +404,13 @@ void SetIndicatorInteractive(ArkUINodeHandle node, ArkUI_Bool value)
void ResetIndicatorInteractive(ArkUINodeHandle node) {}
void SetSwiperNextMargin(ArkUINodeHandle node, ArkUI_Float32 nextMarginValue, ArkUI_Int32 nextMarginUnit)
void SetSwiperNextMargin(
ArkUINodeHandle node, ArkUI_Float32 nextMarginValue, ArkUI_Int32 nextMarginUnit, ArkUI_Bool ignoreBlank)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
SwiperModelNG::SetNextMargin(frameNode, CalcDimension(nextMarginValue, (DimensionUnit)nextMarginUnit));
SwiperModelNG::SetNextMargin(
frameNode, CalcDimension(nextMarginValue, (DimensionUnit)nextMarginUnit), static_cast<bool>(ignoreBlank));
}
void ResetSwiperNextMargin(ArkUINodeHandle node)
@ -419,11 +421,13 @@ void ResetSwiperNextMargin(ArkUINodeHandle node)
SwiperModelNG::SetNextMargin(frameNode, value);
}
void SetSwiperPrevMargin(ArkUINodeHandle node, ArkUI_Float32 prevMarginValue, ArkUI_Int32 prevMarginUnit)
void SetSwiperPrevMargin(
ArkUINodeHandle node, ArkUI_Float32 prevMarginValue, ArkUI_Int32 prevMarginUnit, ArkUI_Bool ignoreBlank)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
SwiperModelNG::SetPreviousMargin(frameNode, CalcDimension(prevMarginValue, (DimensionUnit)prevMarginUnit));
SwiperModelNG::SetPreviousMargin(
frameNode, CalcDimension(prevMarginValue, (DimensionUnit)prevMarginUnit), static_cast<bool>(ignoreBlank));
}
void ResetSwiperPrevMargin(ArkUINodeHandle node)
@ -922,18 +926,26 @@ void SetSwiperToIndex(ArkUINodeHandle node, ArkUI_Int32* values)
CHECK_NULL_VOID(frameNode);
SwiperModelNG::SetSwiperToIndex(frameNode, values[0], values[1]);
}
ArkUI_Float32 GetSwiperPrevMargin(ArkUINodeHandle node, ArkUI_Int32 unit)
void GetSwiperPrevMargin(ArkUINodeHandle node, ArkUI_Int32 unit, ArkUISwiperMarginOptions* options)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
return static_cast<ArkUI_Float32>(SwiperModelNG::GetPreviousMargin(frameNode, unit));
CHECK_NULL_VOID(frameNode);
CHECK_NULL_VOID(options);
SwiperMarginOptions marginOptions;
SwiperModelNG::GetPreviousMargin(frameNode, unit, &marginOptions);
options->margin = static_cast<ArkUI_Float32>(marginOptions.margin);
options->ignoreBlank = static_cast<ArkUI_Bool>(marginOptions.ignoreBlank);
}
ArkUI_Float32 GetSwiperNextMargin(ArkUINodeHandle node, ArkUI_Int32 unit)
void GetSwiperNextMargin(ArkUINodeHandle node, ArkUI_Int32 unit, ArkUISwiperMarginOptions* options)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
return static_cast<ArkUI_Float32>(SwiperModelNG::GetNextMargin(frameNode, unit));
CHECK_NULL_VOID(frameNode);
CHECK_NULL_VOID(options);
SwiperMarginOptions marginOptions;
SwiperModelNG::GetNextMargin(frameNode, unit, &marginOptions);
options->margin = static_cast<ArkUI_Float32>(marginOptions.margin);
options->ignoreBlank = static_cast<ArkUI_Bool>(marginOptions.ignoreBlank);
}
void SetSwiperIndicatorStyle(ArkUINodeHandle node, ArkUISwiperIndicator* indicator)

View File

@ -4367,34 +4367,45 @@ typedef enum {
NODE_SWIPER_CACHED_COUNT,
/**
* @brief Swiper
* @brief Defines the front margin of the wiper.
* The attribute can be set, reset, and obtained as required through APIs.
*
* {@link ArkUI_AttributeItem}\n
* .value[0].f32vp0 \n
* {@link ArkUI_AttributeItem} \n
* .value[0].f32vp
* Format of the {@link ArkUI_AttributeItem} parameter for setting the attribute:\n
* .value[0].f32: the front margin. The unit is vp. The default value is <b>0.0</b>\n
* .value[1]?.i32: whether to ignore blanks, the default value is 0.
* The value <b>1</b> means to ignore blank areas, and <b>0</b> means the opposite. \n
* Format of the return value {@link ArkUI_AttributeItem}:\n
* .value[0].f32: the front margin, the unit is vp. \n
* .value[1].i32: whether to ignore blank areas. The value <b>1</b> means to ignore blank areas, and <b>0</b> means
* the opposite. \n
*/
NODE_SWIPER_PREV_MARGIN,
/**
* @brief Swiper
* @brief Defines the back margin of the wiper.
* The attribute can be set, reset, and obtained as required through APIs.
*
* {@link ArkUI_AttributeItem}\n
* .value[0].f32vp0 \n
* {@link ArkUI_AttributeItem} \n
* .value[0].f32vp
* Format of the {@link ArkUI_AttributeItem} parameter for setting the attribute:\n
* .value[0].f32: the back margin. The unit is vp. The default value is <b>0.0</b>\n
* .value[1]?.i32: whether to ignore blanks, the default value is 0.
* The value <b>1</b> means to ignore blank areas, and <b>0</b> means the opposite. \n
* Format of the return value {@link ArkUI_AttributeItem}:\n
* .value[0].f32: the back margin, the unit is vp. \n
* .value[1].i32: whether to ignore blank areas. The value <b>1</b> means to ignore blank areas, and <b>0</b> means
* the opposite. \n
*/
NODE_SWIPER_NEXT_MARGIN,
/**
* @brief Swiper
* @brief Defines the navigation indicator type of the swiper.
* The attribute can be set, reset, and obtained as required through APIs.
*
* {@link ArkUI_AttributeItem}\n
* .value[0].i32{@link ArkUI_SwiperIndicatorType} \n
* .object{@link ArkUI_SwiperIndicator} \n
* {@link ArkUI_AttributeItem} \n
* .value[0].i32{@link ArkUI_SwiperIndicatorType} \n
* .object{@link ArkUI_SwiperIndicator} \n
* Format of the {@link ArkUI_AttributeItem} parameter for setting the attribute:\n
* .value[0].i32: navigation indicator type, the parameter type is {@link ArkUI_SwiperIndicatorType}.\n
* .object: The parameter type is {@link ArkUI_SwiperIndicator}.\n
* Format of the return value {@link ArkUI_AttributeItem}:\n
* .value[0].i32: navigation indicator type, the parameter type is {@link ArkUI_SwiperIndicatorType}.\n
* .object: The parameter type is {@link ArkUI_SwiperIndicator}.\n
*
*/
NODE_SWIPER_INDICATOR,

View File

@ -42,6 +42,7 @@ struct ArkUI_Node {
void* userData = nullptr;
void* swiperIndicator = nullptr;
void* imageFrameInfos = nullptr;
void* drawableDescriptor = nullptr;
};
struct ArkUI_Context {

View File

@ -6766,16 +6766,21 @@ int32_t SetSwiperToIndex(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
int32_t SetSwiperPrevMargin(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
{
if (item->size == 0) {
auto actualSize = CheckAttributeItemArray(item, REQUIRED_ONE_PARAM);
if (actualSize < NUM_0) {
return ERROR_CODE_PARAM_INVALID;
}
if (LessNotEqual(item->value[0].f32, 0.0f)) {
return ERROR_CODE_PARAM_INVALID;
}
ArkUI_Bool ignoreBlank = DEFAULT_FALSE;
if (actualSize > NUM_1 && (item->value[1].i32 == DEFAULT_TRUE || item->value[1].i32 == DEFAULT_FALSE)) {
ignoreBlank = item->value[1].i32;
}
// already check in entry point.
auto* fullImpl = GetFullImpl();
fullImpl->getNodeModifiers()->getSwiperModifier()->setSwiperPrevMargin(
node->uiNodeHandle, item->value[0].f32, GetDefaultUnit(node, UNIT_VP));
node->uiNodeHandle, item->value[0].f32, GetDefaultUnit(node, UNIT_VP), ignoreBlank);
return ERROR_CODE_NO_ERROR;
}
@ -6791,25 +6796,31 @@ const ArkUI_AttributeItem* GetSwiperPrevMargin(ArkUI_NodeHandle node)
// already check in entry point.
auto* fullImpl = GetFullImpl();
int32_t unit = GetDefaultUnit(node, UNIT_VP);
ArkUI_Float32 value = fullImpl->getNodeModifiers()->getSwiperModifier()->getSwiperPrevMargin(
node->uiNodeHandle, unit);
g_numberValues[0].f32 = value;
g_attributeItem.size = REQUIRED_ONE_PARAM;
ArkUISwiperMarginOptions options;
fullImpl->getNodeModifiers()->getSwiperModifier()->getSwiperPrevMargin(node->uiNodeHandle, unit, &options);
g_numberValues[0].f32 = options.margin;
g_numberValues[1].i32 = options.ignoreBlank;
g_attributeItem.size = REQUIRED_TWO_PARAM;
return &g_attributeItem;
}
int32_t SetSwiperNextMargin(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
{
if (item->size == 0) {
auto actualSize = CheckAttributeItemArray(item, REQUIRED_ONE_PARAM);
if (actualSize < NUM_0) {
return ERROR_CODE_PARAM_INVALID;
}
if (LessNotEqual(item->value[0].f32, 0.0f)) {
return ERROR_CODE_PARAM_INVALID;
}
ArkUI_Bool ignoreBlank = DEFAULT_FALSE;
if (actualSize > NUM_1 && (item->value[1].i32 == DEFAULT_TRUE || item->value[1].i32 == DEFAULT_FALSE)) {
ignoreBlank = item->value[1].i32;
}
// already check in entry point.
auto* fullImpl = GetFullImpl();
fullImpl->getNodeModifiers()->getSwiperModifier()->setSwiperNextMargin(
node->uiNodeHandle, item->value[0].f32, GetDefaultUnit(node, UNIT_VP));
node->uiNodeHandle, item->value[0].f32, GetDefaultUnit(node, UNIT_VP), ignoreBlank);
return ERROR_CODE_NO_ERROR;
}
@ -6825,10 +6836,11 @@ const ArkUI_AttributeItem* GetSwiperNextMargin(ArkUI_NodeHandle node)
// already check in entry point.
auto* fullImpl = GetFullImpl();
int32_t unit = GetDefaultUnit(node, UNIT_VP);
ArkUI_Float32 value = fullImpl->getNodeModifiers()->getSwiperModifier()->getSwiperNextMargin(
node->uiNodeHandle, unit);
g_numberValues[0].f32 = value;
g_attributeItem.size = REQUIRED_ONE_PARAM;
ArkUISwiperMarginOptions options;
fullImpl->getNodeModifiers()->getSwiperModifier()->getSwiperNextMargin(node->uiNodeHandle, unit, &options);
g_numberValues[0].f32 = options.margin;
g_numberValues[1].i32 = options.ignoreBlank;
g_attributeItem.size = REQUIRED_TWO_PARAM;
return &g_attributeItem;
}
@ -9181,6 +9193,7 @@ int32_t SetImageSrc(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
if (!drawableDescriptor) {
return ERROR_CODE_PARAM_INVALID;
}
node->drawableDescriptor = drawableDescriptor;
if (!drawableDescriptor->drawableDescriptor && !drawableDescriptor->resource &&
!drawableDescriptor->animatedDrawableDescriptor) {
return ERROR_CODE_PARAM_INVALID;
@ -10356,6 +10369,9 @@ const ArkUI_AttributeItem* GetImageSpanSrc(ArkUI_NodeHandle node)
auto fullImpl = GetFullImpl();
auto src = fullImpl->getNodeModifiers()->getImageModifier()->getImageSrc(node->uiNodeHandle);
g_attributeItem.string = (src != nullptr ? src : EMPTY_STR.c_str());
if (node->drawableDescriptor) {
g_attributeItem.object = node->drawableDescriptor;
}
return &g_attributeItem;
}
@ -10377,6 +10393,9 @@ const ArkUI_AttributeItem* GetImageSrc(ArkUI_NodeHandle node)
auto fullImpl = GetFullImpl();
auto src = fullImpl->getNodeModifiers()->getImageModifier()->getImageSrc(node->uiNodeHandle);
g_attributeItem.string = (src != nullptr ? src : EMPTY_STR.c_str());
if (node->drawableDescriptor) {
g_attributeItem.object = node->drawableDescriptor;
}
return &g_attributeItem;
}