Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vue-next): add vue3 css style inherit #3838

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ export class HippyElement extends HippyNode {
// style
public style: NativeNodeProps;

// processed style, to refactor on dom
public processedStyle: NativeNodeProps = {};

// events map
public events: NativeNodeProps;

Expand Down Expand Up @@ -874,6 +877,19 @@ export class HippyElement extends HippyNode {
// get styles
let style: NativeNodeProps = this.getNativeStyles();

if (this.parentNode && this.parentNode instanceof HippyElement) {
// 属性继承逻辑实现
// 只继承 color 和 font属性
const parentNodeStyle = this.parentNode.processedStyle;
const styleAttributes = ['color', 'fontSize', 'fontWeight', 'fontFamily', 'fontStyle', 'textAlign', 'lineHeight'];

styleAttributes.forEach((attribute) => {
if (!style[attribute] && parentNodeStyle[attribute]) {
style[attribute] = parentNodeStyle[attribute];
}
});
}

getBeforeRenderToNative()(this, style);

/*
Expand All @@ -892,6 +908,8 @@ export class HippyElement extends HippyNode {
style = { ...updateStyle, ...style };
}

this.processedStyle = style;

const elementExtraAttributes: Partial<NativeNode> = {
name: this.component.name,
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ export class HippyNode extends HippyEventTarget {
// In the case of keep-alive, the node still exists and will be moved to the virtual container
if (child.parentNode && child.parentNode !== this) {
child.parentNode.removeChild(child);
return;
}

// If the node is already mounted, remove it first, but do not remove when is hydrate.
Expand Down
Loading