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

🎨 fix: recycler view with overflow error #662

Merged
merged 31 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
302eb2c
:art: fix: recycler view with overflow error
wssgcg1213 Sep 7, 2021
2544df9
:white_check_mark: test: the new effect is right
wssgcg1213 Sep 7, 2021
8647fae
:bug: fix: recycler remove item
wssgcg1213 Sep 7, 2021
989d570
:recycle: refactor: debounce scroll event trigger
wssgcg1213 Sep 8, 2021
d159a95
:recycle: chore: schedule frame
wssgcg1213 Sep 8, 2021
800cee6
:bug: fix: apply sticky sync
wssgcg1213 Sep 8, 2021
d8ec42f
:recycle: chore: improve code performance
wssgcg1213 Sep 8, 2021
c1b84bc
:recycle: chore: using dispatch
wssgcg1213 Sep 8, 2021
d2a0089
:bug: fix: image resize multi times if not on screen
wssgcg1213 Sep 8, 2021
89e5e99
:bug: fix: recycler view
wssgcg1213 Sep 9, 2021
718ef60
:bug: fix: sliver scroll event
wssgcg1213 Sep 10, 2021
cb6aeda
:bug: fix: recycler use render box
wssgcg1213 Sep 10, 2021
4e1b97e
:bug: fix: scroll width and scroll height, with sliver tests
wssgcg1213 Sep 10, 2021
0099bc5
:white_check_mark: test: add test spec snapshot
wssgcg1213 Sep 10, 2021
b97c070
:white_check_mark: test: add test case for insert before
wssgcg1213 Sep 10, 2021
b956e72
:recycle: chore: remove comment code
wssgcg1213 Sep 10, 2021
ccc1a21
:recycle: chore: update code preview
wssgcg1213 Sep 13, 2021
91b78cc
:art: Merge branch 'main' into fix/recycler-list-view
wssgcg1213 Sep 13, 2021
eec9be5
:bug: fix: sliver element scroll
wssgcg1213 Sep 13, 2021
0dba3f9
:bug: fix: reset x and y
wssgcg1213 Sep 13, 2021
743805c
:bug: fix: scrollX is not removed.
wssgcg1213 Sep 13, 2021
3104118
:bug: fix: clip set to false for recycler
wssgcg1213 Sep 14, 2021
bb97658
Merge branch 'fix/recycler-list-view' of github.com:openkraken/kraken…
wssgcg1213 Sep 14, 2021
e98267a
:bug: fix: not to dispose position
wssgcg1213 Sep 14, 2021
d7214d9
:art: chore: improve comments
wssgcg1213 Sep 14, 2021
4898e83
:iphone: chore: remove empty line.
wssgcg1213 Sep 14, 2021
8c154c1
:recycle: chore: remove unused method.
wssgcg1213 Sep 14, 2021
40a9242
:recycle: chore: remove empty line.
wssgcg1213 Sep 14, 2021
13ad55f
:recycle: chore: add comments for recycler.
wssgcg1213 Sep 14, 2021
c9ad04b
:art: chore: remove unused code.
wssgcg1213 Sep 14, 2021
b861c0a
:recycle: chore: rename insertSliverChild.
wssgcg1213 Sep 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions integration_tests/specs/css/css-display/sliver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,33 @@ describe('display sliver', () => {
await snapshot();
});

it('scrollTop', async () => {
const container = createSliverBasicCase();

container.scrollBy(0, 200);
expect(container.scrollTop).toEqual(200);

container.scrollBy(0, -150);
expect(container.scrollTop).toEqual(50);
});

it('scrollHeight', async () => {
const container = createSliverBasicCase();

container.scrollBy(0, 200);
expect(container.scrollHeight).toEqual(100 * 99);
});

it('child contains Comment and Text', async () => {
const container = createSliverBasicCase();
const comment = document.createComment('foo');
container.appendChild(comment);
container.appendChild(document.createTextNode('hello'));

// No error occurred, pass.
await snapshot();
});

it('continuous scroll works', async () => {
const container = createSliverBasicCase();

Expand All @@ -51,6 +78,27 @@ describe('display sliver', () => {
await snapshot();
});

it('insertBefore with right order', async () => {
var d = document.createElement('div');

for (var i = 0; i < 100; i ++) {
var e = document.createElement('div');
e.style.background = 'red';
e.style.width = e.style.height = '99px';
e.appendChild(document.createTextNode(i + ''));
d.insertBefore(e, d.firstChild);
}

d.style.display = 'sliver';
d.style.width = '100px';
d.style.height = '150px';

document.body.appendChild(d);

// Order from 99 -> 0
await snapshot();
});

it('should works with positioned element of no top and left', async () => {
let div;
div = createElement(
Expand Down
2 changes: 1 addition & 1 deletion kraken/lib/src/bridge/to_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ nativeDynamicLibrary.lookup<NativeFunction<NativeEvaluateScripts>>('evaluateScri
final DartParseHTML _parseHTML =
nativeDynamicLibrary.lookup<NativeFunction<NativeParseHTML>>('parseHTML').asFunction();

void evaluateScripts(int contextId, String code, String url, int line) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

launcher 里面 lineOffset 也没用了吧?看起来 lineOffset 定义了 0 传递进去就没了,目前应该没有指定起始位置的需求。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

跟 JSC API 对齐参数的原因吧, @andycall 看下还要不要

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对,参数是需要传递的,这里默认 0 没问题,我说调用的地方也去掉一下。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

调用的地方 @andycall 的意思应该是预留的, 给外层传递用的, 放在抽象类里面提供的是默认值
image

void evaluateScripts(int contextId, String code, String url, [int line = 0]) {
if(KrakenController.getControllerOfJSContextId(contextId) == null) {
return;
}
Expand Down
41 changes: 30 additions & 11 deletions kraken/lib/src/css/overflow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ CSSOverflowType _getOverflowType(String definition) {
}
}

typedef ScrollListener = void Function(double scrollTop, AxisDirection axisDirection);

mixin CSSOverflowStyleMixin on RenderStyleBase {
CSSOverflowType _overflowX = CSSOverflowType.visible;
CSSOverflowType get overflowX {
Expand Down Expand Up @@ -87,7 +85,8 @@ mixin CSSOverflowMixin on ElementBase {
// House content which can be scrolled.
RenderLayoutBox? scrollingContentLayoutBox;

void updateRenderOverflow(Element element, ScrollListener scrollListener) {
void updateRenderOverflow(Element element) {
ScrollListener scrollListener = element.elementDelegate.handleScroll;
CSSStyleDeclaration style = element.style;
RenderBoxModel renderBoxModel = element.renderBoxModel!;
RenderStyle renderStyle = renderBoxModel.renderStyle;
Expand Down Expand Up @@ -155,6 +154,11 @@ mixin CSSOverflowMixin on ElementBase {
break;
}

// Recycler layout not need repaintBoundary, which handle it self.
wssgcg1213 marked this conversation as resolved.
Show resolved Hide resolved
if (renderBoxModel is RenderRecyclerLayout) {
return;
}

renderBoxModel.scrollListener = scrollListener;
renderBoxModel.pointerListener = _pointerListener;

Expand Down Expand Up @@ -267,7 +271,7 @@ mixin CSSOverflowMixin on ElementBase {
if (parent is RenderObjectWithChildMixin<RenderBox>) {
parent.child = null;
} else if (parent is ContainerRenderObjectMixin) {
ContainerBoxParentData parentData = renderObject!.parentData as ContainerBoxParentData<RenderObject>;
ContainerParentDataMixin parentData = renderObject!.parentData as ContainerParentDataMixin<RenderObject>;
RenderObject? previousSibling = parentData.previousSibling;
parent.remove(renderObject);
return previousSibling;
Expand Down Expand Up @@ -298,31 +302,45 @@ mixin CSSOverflowMixin on ElementBase {
}

double get scrollTop {
if (_scrollableY != null) {
return _scrollableY!.position?.pixels ?? 0;
KrakenScrollable? scrollableY = _getScrollable(Axis.vertical);
if (scrollableY != null) {
return scrollableY.position?.pixels ?? 0;
}
return 0.0;
}

set scrollTop(double value) {
scrollTo(y: value);
}

double get scrollLeft {
if (_scrollableX != null) {
return _scrollableX!.position?.pixels ?? 0;
KrakenScrollable? scrollableX = _getScrollable(Axis.horizontal);
if (scrollableX != null) {
return scrollableX.position?.pixels ?? 0;
}
return 0.0;
}

set scrollLeft(double value) {
scrollTo(x: value);
}

get scrollHeight {
double get scrollHeight {
KrakenScrollable? scrollable = _getScrollable(Axis.vertical);
if (scrollable?.position?.maxScrollExtent != null) {
// Viewport height + maxScrollExtent
return renderBoxModel!.clientHeight + scrollable!.position!.maxScrollExtent!;
}

Size scrollContainerSize = renderBoxModel!.scrollableSize;
return scrollContainerSize.height;
}

get scrollWidth {
double get scrollWidth {
KrakenScrollable? scrollable = _getScrollable(Axis.horizontal);
if (scrollable?.position?.maxScrollExtent != null) {
return renderBoxModel!.clientWidth + scrollable!.position!.maxScrollExtent!;
}
Size scrollContainerSize = renderBoxModel!.scrollableSize;
return scrollContainerSize.width;
}
Expand All @@ -349,7 +367,8 @@ mixin CSSOverflowMixin on ElementBase {
KrakenScrollable? _getScrollable(Axis direction) {
KrakenScrollable? scrollable;
if (renderer is RenderRecyclerLayout) {
scrollable = (renderer as RenderRecyclerLayout).scrollable;
RenderRecyclerLayout recyclerLayout = renderer as RenderRecyclerLayout;
scrollable = direction == recyclerLayout.axis ? recyclerLayout.scrollable : null;
} else {
if (direction == Axis.horizontal) {
scrollable = _scrollableX;
Expand Down
10 changes: 5 additions & 5 deletions kraken/lib/src/css/sliver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ mixin CSSSliverMixin on RenderStyleBase {

if (renderBoxModel is RenderRecyclerLayout) {
RenderRecyclerLayout recyclerLayout = renderBoxModel as RenderRecyclerLayout;

AxisDirection axisDirection = RenderRecyclerLayout.getAxisDirection(value);

recyclerLayout.scrollable = KrakenScrollable(axisDirection: axisDirection);
RenderViewport renderViewport = recyclerLayout.renderViewport!;
renderViewport.axisDirection = axisDirection;
renderViewport.crossAxisDirection = RenderRecyclerLayout.getCrossAxisDirection(value);
renderViewport.offset = recyclerLayout.scrollable!.position!;
recyclerLayout.viewport
..axisDirection = axisDirection
..crossAxisDirection = RenderRecyclerLayout.getCrossAxisDirection(value)
..offset = recyclerLayout.scrollable.position!;

recyclerLayout.markNeedsLayout();
}
Expand Down