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

Fixed layout recalculation for text #314

Merged
merged 1 commit into from
Aug 15, 2018
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
21 changes: 18 additions & 3 deletions ReactQt/runtime/src/componentmanagers/textmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,21 @@ void TextManager::updateMeasureFunction(QQuickItem* textItem) {
bool childIsTopReactTextInTextHierarchy = textItem->property("textIsTopInBlock").toBool();

if (childIsTopReactTextInTextHierarchy) {
flexbox->setMeasureFunction([=](YGNodeRef, float width, YGMeasureMode, float, YGMeasureMode) {
flexbox->setMeasureFunction([=](
YGNodeRef /*node*/, float width, YGMeasureMode /*widthMode*/, float height, YGMeasureMode /*heightMode*/) {
resizeToWidth(textItem, width);
resizeToHeight(textItem, height);
float h = textItem->height();
float w = textItem->width();
float ch = textItem->property("contentHeight").toDouble();
return YGSize{w, ch};
return YGSize{w, h};
});
} else {
flexbox->setMeasureFunction(nullptr);
}
}

void TextManager::resizeToWidth(QQuickItem* textItem, double width) {
textItem->setWidth(width);
double contentWidth = textItem->property("contentWidth").value<double>();
double sw = 0;
if (std::isnan(width)) {
Expand All @@ -92,6 +95,18 @@ void TextManager::resizeToWidth(QQuickItem* textItem, double width) {
textItem->setWidth(sw);
}

void TextManager::resizeToHeight(QQuickItem* textItem, double height) {
textItem->setHeight(height);
double contentHeight = textItem->property("contentHeight").value<double>();
double sh = 0;
if (std::isnan(height)) {
sh = contentHeight;
} else {
sh = contentHeight == 0 ? height : qMin(contentHeight, height);
}
textItem->setHeight(sh);
}

QVariant TextManager::nestedPropertyValue(QQuickItem* item, const QString& propertyName) {
// return value if it is explicitly set on current item
if (propertyExplicitlySet(item, propertyName)) {
Expand Down
1 change: 1 addition & 0 deletions ReactQt/runtime/src/componentmanagers/textmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class TextManager : public RawTextManager {

typedef std::map<QString, QVariant> PropertyMap;
static void resizeToWidth(QQuickItem* textItem, double width);
static void resizeToHeight(QQuickItem* textItem, double height);

public slots:
QVariant nestedPropertyValue(QQuickItem* item, const QString& propertyName);
Expand Down
4 changes: 0 additions & 4 deletions ReactQt/runtime/src/componentmanagers/viewmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ void ViewManager::addChildItem(QQuickItem* container, QQuickItem* child, int pos
}

QQuickItem* ViewManager::view(const QVariantMap& properties) const {
qDebug() << "!!!! ViewManager::view props: " << properties;
QQuickItem* newView = createView(properties);
if (newView) {
configureView(newView);
Expand Down Expand Up @@ -115,15 +114,12 @@ void ViewManager::sendOnLayoutToJs(QQuickItem* view, float x, float y, float wid
if (!view)
return;

qDebug() << " call of ViewManager::sendOnLayoutToJs for " << view;

notifyJsAboutEvent(tag(view),
EVENT_ONLAYOUT,
QVariantMap{{"layout", QVariantMap{{"x", x}, {"y", y}, {"width", width}, {"height", height}}}});
}

QQuickItem* ViewManager::createView(const QVariantMap& properties) const {
qDebug() << "!!!! ViewManager::createView props: " << properties;
QQuickItem* item = createQMLItemFromSourceFile(m_bridge->qmlEngine(), QUrl(qmlComponentFile(properties)));
if (item == nullptr) {
qCritical() << QString("Can't create QML item for componenet %1").arg(qmlComponentFile(properties));
Expand Down
4 changes: 4 additions & 0 deletions ReactQt/runtime/src/layout/flexbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,10 @@ bool Flexbox::isDirty() {
return YGNodeIsDirty(d_ptr->m_node);
}

void Flexbox::markDirty() {
YGNodeMarkDirty(d_ptr->m_node);
}

void Flexbox::printFlexboxHierarchy() {
d_ptr->printNode();
}
Expand Down
5 changes: 4 additions & 1 deletion ReactQt/runtime/src/layout/flexbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Flexbox : public QObject {
Q_PROPERTY(QString p_overflow READ overflow WRITE setOverflow NOTIFY overflowChanged)
Q_PROPERTY(QString p_position READ position WRITE setPosition NOTIFY positionChanged)
Q_PROPERTY(QString p_direction READ direction WRITE setDirection NOTIFY directionChanged)
Q_PROPERTY(QString isDirty READ isDirty NOTIFY isDirtyChanged)
Q_PROPERTY(bool isDirty READ isDirty NOTIFY isDirtyChanged)

signals:
void widthChanged();
Expand Down Expand Up @@ -235,6 +235,9 @@ class Flexbox : public QObject {
void setDirection(const QString& value);
bool isDirty();

public slots:
void markDirty();

private:
QScopedPointer<FlexboxPrivate> d_ptr;
};
Expand Down
1 change: 1 addition & 0 deletions ReactQt/runtime/src/qml/ReactText.qml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ TextEdit {
}
}
decoratedText = htmlString;
textRoot.flexbox.markDirty();
}

function isText(obj)
Expand Down