Pass locale along to RenderParagraph (#17879)

This commit is contained in:
Hans Muller 2018-05-31 11:01:24 -07:00 committed by GitHub
parent 49bcda52a2
commit f1e4defbbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:ui' as ui show Gradient, Shader, TextBox; import 'dart:ui' as ui show Gradient, Shader, TextBox, Locale;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
@ -44,6 +44,7 @@ class RenderParagraph extends RenderBox {
TextOverflow overflow: TextOverflow.clip, TextOverflow overflow: TextOverflow.clip,
double textScaleFactor: 1.0, double textScaleFactor: 1.0,
int maxLines, int maxLines,
ui.Locale locale,
}) : assert(text != null), }) : assert(text != null),
assert(text.debugAssertIsValid()), assert(text.debugAssertIsValid()),
assert(textAlign != null), assert(textAlign != null),
@ -61,6 +62,7 @@ class RenderParagraph extends RenderBox {
textScaleFactor: textScaleFactor, textScaleFactor: textScaleFactor,
maxLines: maxLines, maxLines: maxLines,
ellipsis: overflow == TextOverflow.ellipsis ? _kEllipsis : null, ellipsis: overflow == TextOverflow.ellipsis ? _kEllipsis : null,
locale: locale,
); );
final TextPainter _textPainter; final TextPainter _textPainter;
@ -174,6 +176,15 @@ class RenderParagraph extends RenderBox {
markNeedsLayout(); markNeedsLayout();
} }
ui.Locale get locale => _textPainter.locale;
set locale(ui.Locale value) {
if (_textPainter.locale == value)
return;
_textPainter.locale = locale;
_overflowShader = null;
markNeedsLayout();
}
void _layoutText({ double minWidth: 0.0, double maxWidth: double.infinity }) { void _layoutText({ double minWidth: 0.0, double maxWidth: double.infinity }) {
final bool widthMatters = softWrap || overflow == TextOverflow.ellipsis; final bool widthMatters = softWrap || overflow == TextOverflow.ellipsis;
_textPainter.layout(minWidth: minWidth, maxWidth: widthMatters ? maxWidth : double.infinity); _textPainter.layout(minWidth: minWidth, maxWidth: widthMatters ? maxWidth : double.infinity);

View File

@ -10,6 +10,7 @@ import 'package:flutter/services.dart';
import 'debug.dart'; import 'debug.dart';
import 'framework.dart'; import 'framework.dart';
import 'localizations.dart';
export 'package:flutter/animation.dart'; export 'package:flutter/animation.dart';
export 'package:flutter/foundation.dart' show export 'package:flutter/foundation.dart' show
@ -4341,6 +4342,7 @@ class RichText extends LeafRenderObjectWidget {
overflow: overflow, overflow: overflow,
textScaleFactor: textScaleFactor, textScaleFactor: textScaleFactor,
maxLines: maxLines, maxLines: maxLines,
locale: Localizations.localeOf(context, nullOk: true),
); );
} }
@ -4354,7 +4356,8 @@ class RichText extends LeafRenderObjectWidget {
..softWrap = softWrap ..softWrap = softWrap
..overflow = overflow ..overflow = overflow
..textScaleFactor = textScaleFactor ..textScaleFactor = textScaleFactor
..maxLines = maxLines; ..maxLines = maxLines
..locale = Localizations.localeOf(context, nullOk: true);
} }
@override @override