forked from cocos/cocos-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
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
add scroll view inspector #28
Merged
VisualSJ
merged 5 commits into
VisualSJ:develop
from
chichinohaha:add-scroll-view-inspector
Apr 6, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6e62e82
add scroll view inspector
chichinohaha 66cf361
Merge branch 'develop' into add-scroll-view-inspector
chichinohaha cfa82fd
format html
chichinohaha eccc277
Update scroll-view.js
VisualSJ 86361b4
Merge branch 'develop' into add-scroll-view-inspector
VisualSJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-return */ | ||
const propUtils = require('../utils/prop'); | ||
|
||
const excludeList = [ | ||
'content', 'horizontal', 'vertical', 'inertia', 'brake', 'elastic', | ||
'bounceDuration', 'horizontalScrollBar', 'verticalScrollBar', | ||
'scrollEvents', 'cancelInnerEvents', | ||
]; | ||
|
||
exports.template = ` | ||
<div class="scroll-view-component"> | ||
<ui-prop type="dump" key="content"></ui-prop> | ||
<ui-prop type="dump" key="horizontal"></ui-prop> | ||
<ui-prop type="dump" key="vertical"></ui-prop> | ||
<ui-prop type="dump" key="inertia"></ui-prop> | ||
<ui-prop type="dump" showflag="inertia" key="brake"></ui-prop> | ||
<ui-prop type="dump" key="elastic"></ui-prop> | ||
<ui-prop type="dump" showflag="elastic" key="bounceDuration"></ui-prop> | ||
<ui-prop type="dump" showflag="horizontal" key="horizontalScrollBar"></ui-prop> | ||
<ui-prop type="dump" showflag="vertical" key="verticalScrollBar"></ui-prop> | ||
<ui-prop type="dump" key="scrollEvents"></ui-prop> | ||
<ui-prop type="dump" key="cancelInnerEvents"></ui-prop> | ||
|
||
<!-- Render other data that is not taken over --> | ||
<div id="customProps"></div> | ||
</div> | ||
`; | ||
|
||
exports.$ = { | ||
customProps: '#customProps', | ||
}; | ||
|
||
const uiElements = { | ||
baseProps: { | ||
ready () { | ||
this.$.baseProps = this.$this.querySelectorAll('ui-prop:not(.customProp)'); | ||
this.$.baseProps.forEach((prop) => { | ||
prop.addEventListener('change-dump', () => { | ||
uiElements.baseProps.update.call(this); | ||
}); | ||
}); | ||
}, | ||
update () { | ||
if (!this.$.baseProps) { | ||
uiElements.baseProps.ready.call(this); | ||
} | ||
this.$.baseProps.forEach((element) => { | ||
const key = element.getAttribute('key'); | ||
let isShow = this.dump.value[key].visible; | ||
if (isShow) { | ||
element.render(this.dump.value[key]); | ||
} | ||
if (element.hasAttribute('showflag')) { | ||
const showflag = element.getAttribute('showflag'); | ||
isShow = isShow && this.dump.value[showflag] && this.dump.value[showflag].value; | ||
} | ||
element.style = isShow ? '' : 'display: none;'; | ||
}); | ||
}, | ||
}, | ||
customProps: { | ||
update () { | ||
this.$.customProps.replaceChildren(...propUtils.getCustomPropElements(excludeList, this.dump, (element, prop) => { | ||
element.className = 'customProp'; | ||
if (prop.dump.visible) { | ||
element.render(prop.dump); | ||
} | ||
element.style = prop.dump.visible ? '' : 'display: none;'; | ||
})); | ||
}, | ||
}, | ||
}; | ||
|
||
exports.ready = function () { | ||
for (const key in uiElements) { | ||
const element = uiElements[key]; | ||
if (typeof element.ready === 'function') { | ||
element.ready.call(this); | ||
} | ||
} | ||
}; | ||
|
||
exports.update = function (dump) { | ||
for (const key in dump.value) { | ||
const info = dump.value[key]; | ||
if (dump.values) { | ||
info.values = dump.values.map((value) => value[key].value); | ||
} | ||
} | ||
this.dump = dump; | ||
for (const key in uiElements) { | ||
const element = uiElements[key]; | ||
if (typeof element.update === 'function') { | ||
element.update.call(this); | ||
} | ||
} | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嵌套 ui-prop 就跪了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不会啊,ready只会在面板ready的时候调用一次