mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Revert method channel platform resolved locale (flutter/engine#19136)
This commit is contained in:
parent
03b91c7af2
commit
855fa8fde8
@ -88,22 +88,6 @@ void _updateLocales(List<String> locales) {
|
||||
_invoke(window.onLocaleChanged, window._onLocaleChangedZone);
|
||||
}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
// ignore: unused_element
|
||||
void _updatePlatformResolvedLocale(List<String> localeData) {
|
||||
if (localeData.length != 4) {
|
||||
return;
|
||||
}
|
||||
final String countryCode = localeData[1];
|
||||
final String scriptCode = localeData[2];
|
||||
|
||||
window._platformResolvedLocale = Locale.fromSubtags(
|
||||
languageCode: localeData[0],
|
||||
countryCode: countryCode.isEmpty ? null : countryCode,
|
||||
scriptCode: scriptCode.isEmpty ? null : scriptCode,
|
||||
);
|
||||
}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
// ignore: unused_element
|
||||
void _updateUserSettingsData(String jsonData) {
|
||||
|
||||
@ -796,19 +796,6 @@ class Window {
|
||||
List<Locale>? get locales => _locales;
|
||||
List<Locale>? _locales;
|
||||
|
||||
/// The locale that the platform's native locale resolution system resolves to.
|
||||
///
|
||||
/// This value may differ between platforms and is meant to allow Flutter's locale
|
||||
/// resolution algorithms access to a locale that is consistent with other apps
|
||||
/// on the device. Using this property is optional.
|
||||
///
|
||||
/// This value may be used in a custom [localeListResolutionCallback] or used directly
|
||||
/// in order to arrive at the most appropriate locale for the app.
|
||||
///
|
||||
/// See [locales], which is the list of locales the user/device prefers.
|
||||
Locale? get platformResolvedLocale => _platformResolvedLocale;
|
||||
Locale? _platformResolvedLocale;
|
||||
|
||||
/// Performs the platform-native locale resolution.
|
||||
///
|
||||
/// Each platform may return different results.
|
||||
|
||||
@ -224,19 +224,6 @@ void Window::UpdateLocales(const std::vector<std::string>& locales) {
|
||||
}));
|
||||
}
|
||||
|
||||
void Window::UpdatePlatformResolvedLocale(
|
||||
const std::vector<std::string>& locale) {
|
||||
std::shared_ptr<tonic::DartState> dart_state = library_.dart_state().lock();
|
||||
if (!dart_state)
|
||||
return;
|
||||
tonic::DartState::Scope scope(dart_state);
|
||||
tonic::LogIfError(tonic::DartInvokeField(
|
||||
library_.value(), "_updatePlatformResolvedLocale",
|
||||
{
|
||||
tonic::ToDart<std::vector<std::string>>(locale),
|
||||
}));
|
||||
}
|
||||
|
||||
void Window::UpdateUserSettingsData(const std::string& data) {
|
||||
std::shared_ptr<tonic::DartState> dart_state = library_.dart_state().lock();
|
||||
if (!dart_state)
|
||||
|
||||
@ -78,7 +78,6 @@ class Window final {
|
||||
void DidCreateIsolate();
|
||||
void UpdateWindowMetrics(const ViewportMetrics& metrics);
|
||||
void UpdateLocales(const std::vector<std::string>& locales);
|
||||
void UpdatePlatformResolvedLocale(const std::vector<std::string>& locale);
|
||||
void UpdateUserSettingsData(const std::string& data);
|
||||
void UpdateLifecycleState(const std::string& data);
|
||||
void UpdateSemanticsEnabled(bool enabled);
|
||||
|
||||
@ -303,10 +303,6 @@ class EngineWindow extends ui.Window {
|
||||
return locales;
|
||||
}
|
||||
|
||||
/// On the web "platform" is the browser, so it's the same as [locale].
|
||||
@override
|
||||
ui.Locale get platformResolvedLocale => locale;
|
||||
|
||||
/// Engine code should use this method instead of the callback directly.
|
||||
/// Otherwise zones won't work properly.
|
||||
void invokeOnLocaleChanged() {
|
||||
|
||||
@ -604,18 +604,6 @@ abstract class Window {
|
||||
/// observe when this value changes.
|
||||
List<Locale>? get locales;
|
||||
|
||||
/// The locale that the platform's native locale resolution system resolves to.
|
||||
///
|
||||
/// This value may differ between platforms and is meant to allow flutter locale
|
||||
/// resolution algorithms to into resolving consistently with other apps on the
|
||||
/// device.
|
||||
///
|
||||
/// This value may be used in a custom [localeListResolutionCallback] or used directly
|
||||
/// in order to arrive at the most appropriate locale for the app.
|
||||
///
|
||||
/// See [locales], which is the list of locales the user/device prefers.
|
||||
Locale? get platformResolvedLocale;
|
||||
|
||||
/// Performs the platform-native locale resolution.
|
||||
///
|
||||
/// Each platform may return different results.
|
||||
|
||||
@ -131,8 +131,6 @@ std::unique_ptr<RuntimeController> RuntimeController::Clone() const {
|
||||
bool RuntimeController::FlushRuntimeStateToIsolate() {
|
||||
return SetViewportMetrics(window_data_.viewport_metrics) &&
|
||||
SetLocales(window_data_.locale_data) &&
|
||||
SetPlatformResolvedLocale(
|
||||
window_data_.platform_resolved_locale_data) &&
|
||||
SetSemanticsEnabled(window_data_.semantics_enabled) &&
|
||||
SetAccessibilityFeatures(window_data_.accessibility_feature_flags_) &&
|
||||
SetUserSettingsData(window_data_.user_settings_data) &&
|
||||
@ -161,18 +159,6 @@ bool RuntimeController::SetLocales(
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RuntimeController::SetPlatformResolvedLocale(
|
||||
const std::vector<std::string>& locale_data) {
|
||||
window_data_.platform_resolved_locale_data = locale_data;
|
||||
|
||||
if (auto* window = GetWindowIfAvailable()) {
|
||||
window->UpdatePlatformResolvedLocale(locale_data);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RuntimeController::SetUserSettingsData(const std::string& data) {
|
||||
window_data_.user_settings_data = data;
|
||||
|
||||
|
||||
@ -161,23 +161,6 @@ class RuntimeController final : public WindowClient {
|
||||
///
|
||||
bool SetLocales(const std::vector<std::string>& locale_data);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @brief Forward the specified locale data to the running isolate. If
|
||||
/// the isolate is not running, this data will be saved and
|
||||
/// flushed to the isolate when it starts running.
|
||||
///
|
||||
///
|
||||
/// @deprecated The persistent isolate data must be used for this purpose
|
||||
/// instead.
|
||||
///
|
||||
/// @param[in] locale_data The locale data. This should consist of a vector
|
||||
/// of 4 strings, representing languageCode, contryCode,
|
||||
/// scriptCode, and variant of the locale.
|
||||
///
|
||||
/// @return If the locale data was forwarded to the running isolate.
|
||||
///
|
||||
bool SetPlatformResolvedLocale(const std::vector<std::string>& locale_data);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @brief Forward the user settings data to the running isolate. If the
|
||||
/// isolate is not running, this data will be saved and flushed to
|
||||
|
||||
@ -36,7 +36,6 @@ struct WindowData {
|
||||
std::string script_code;
|
||||
std::string variant_code;
|
||||
std::vector<std::string> locale_data;
|
||||
std::vector<std::string> platform_resolved_locale_data;
|
||||
std::string user_settings_data = "{}";
|
||||
std::string lifecycle_state;
|
||||
bool semantics_enabled = false;
|
||||
|
||||
@ -388,24 +388,6 @@ bool Engine::HandleLocalizationPlatformMessage(PlatformMessage* message) {
|
||||
}
|
||||
|
||||
return runtime_controller_->SetLocales(locale_data);
|
||||
} else if (method->value == "setPlatformResolvedLocale") {
|
||||
// Decode and pass the single locale data onwards to dart.
|
||||
auto args = root.FindMember("args");
|
||||
if (args == root.MemberEnd() || !args->value.IsArray())
|
||||
return false;
|
||||
|
||||
if (args->value.Size() != strings_per_locale)
|
||||
return false;
|
||||
|
||||
std::vector<std::string> locale_data;
|
||||
if (!args->value[0].IsString() || !args->value[1].IsString())
|
||||
return false;
|
||||
locale_data.push_back(args->value[0].GetString());
|
||||
locale_data.push_back(args->value[1].GetString());
|
||||
locale_data.push_back(args->value[2].GetString());
|
||||
locale_data.push_back(args->value[3].GetString());
|
||||
|
||||
return runtime_controller_->SetPlatformResolvedLocale(locale_data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -48,20 +48,4 @@ public class LocalizationChannel {
|
||||
}
|
||||
channel.invokeMethod("setLocale", data);
|
||||
}
|
||||
|
||||
/** Send the given {@code platformResolvedLocale} to Dart. */
|
||||
public void sendPlatformResolvedLocales(Locale platformResolvedLocale) {
|
||||
Log.v(TAG, "Sending Locales to Flutter.");
|
||||
// Send platformResolvedLocale first as it may be used in the callback
|
||||
// triggered by the user supported locales being updated/set.
|
||||
if (platformResolvedLocale != null) {
|
||||
List<String> platformResolvedLocaleData = new ArrayList<>();
|
||||
platformResolvedLocaleData.add(platformResolvedLocale.getLanguage());
|
||||
platformResolvedLocaleData.add(platformResolvedLocale.getCountry());
|
||||
platformResolvedLocaleData.add(
|
||||
Build.VERSION.SDK_INT >= 21 ? platformResolvedLocale.getScript() : "");
|
||||
platformResolvedLocaleData.add(platformResolvedLocale.getVariant());
|
||||
channel.invokeMethod("setPlatformResolvedLocale", platformResolvedLocaleData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,10 +33,6 @@ FLUTTER_ASSERT_ARC
|
||||
XCTAssertTrue([textInputSemanticsObject waitForExistenceWithTimeout:timeout]);
|
||||
|
||||
[textInputSemanticsObject tap];
|
||||
|
||||
// [NSLocale currentLocale] always includes a country code.
|
||||
textInputSemanticsObject = [self.application.textFields matchingIdentifier:@"en_US"].element;
|
||||
XCTAssertTrue([textInputSemanticsObject waitForExistenceWithTimeout:timeout]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@ -78,7 +78,7 @@ class LocaleInitialization extends Scenario {
|
||||
String label;
|
||||
switch(_tapCount) {
|
||||
case 1: {
|
||||
label = window.platformResolvedLocale.toString();
|
||||
// Set label to string data we wish to pass on first frame.
|
||||
break;
|
||||
}
|
||||
// Expand for other test cases.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user