问题
resizeable_dialog.html
<link rel="import" href="../../packages/polymer/polymer.html">
<link rel="import" href="../../packages/paper_elements/paper_dialog.html">
<link rel="import" href="../../packages/paper_elements/paper_button.html">
<link rel="import" href="../../packages/paper_elements/paper_tabs.html">
<link rel="import" href="../../packages/paper_elements/paper_tab.html">
<link rel="import" href="../../packages/paper_elements/paper_icon_button.html">
<link rel="import" href="../../packages/core_elements/core_toolbar.html">
<link rel="import" href="../../packages/core_elements/core_pages.html">
<polymer-element name="resizeable-dialog">
<template>
<style>
:host {
display: block;
}
</style>
<paper-button on-click="{{open}}">Open Dialog</paper-button>
<paper-dialog id="dialog" transition="core-transition-bottom" backdrop>
<paper-tabs selected="{{selected}}">
<paper-tab>Page 1</paper-tab>
<paper-tab>Page 2</paper-tab>
</paper-tabs>
<section>
<core-pages selected="{{selected}}">
<div style="width: 100px; height: 100px;">
<div>Page 1: 100x100</div>
<paper-button on-click="{{notifyResize}}">Call 'notifyResize'</paper-button>
</div>
<div style="width: 400px; height: 400px;">
<div>Page 2: 400x400</div>
<paper-button on-click="{{notifyResize}}">Call 'notifyResize'</paper-button>
</div>
</core-pages>
</section>
</paper-dialog>
</template>
<script type="application/dart" src="resizeable_dialog.dart"></script>
</polymer-element>
resizeable_dialog.dart
library resizable_dialog;
import 'package:polymer/polymer.dart';
import 'package:paper_elements/paper_dialog.dart';
@CustomTag('resizeable-dialog')
class ResizeableDialog extends PolymerElement {
ResizeableDialog.created() : super.created();
@observable int selected = 0;
notifyResize() {
$['dialog'] as PaperDialog..notifyResize();
print('"notifyResize" called.');
}
open() {
$['dialog'] as PaperDialog..open();
}
}
This is my dialog, I think you get the idea with the tabbar. My problem is that the <paper-dialog>
calculates its dimensions at some point before it gets shown. However, since my <core-pages>
can have different width & height, I have to resize the dialog whenever the user selects a tab to ensure, that the whole content of the current selected page is visible.
The method <paper-dialog>.notifyResize()
does not exist in Dart for some reasons. It's specified here, in the paper-elements
documentation but I cannot invoke it, since it does not exist in Dart.
How can I do this? How can I ask the dialog to re-measure its dimensions?
回答1:
You should be able to work around like
import 'dart:js' as js;
...
new js.JsObject.fromBrowserObject($['dialog'])
.callMethod('notifyResize', []);
or
import 'package:paper_elements/paper_dialog.dart';
...
($['dialog'] as PaperDialog).jsElement
.callMethod('notifyResize', []);
Please create a bug report in the github.com/dart-lang/paper-elements repo (or core-elements, because I think this function should be inherited from core-overlay)
来源:https://stackoverflow.com/questions/30009091/resize-paper-dialog-when-selecting-paper-tab-inside-the-dialog