fix(ios-searchbar): fix searchbar auto sizing in iOS11 (#5658)

This commit is contained in:
Manol Donev
2018-04-12 14:13:21 +03:00
committed by GitHub
parent 893cbb4211
commit 555e5920c3
3 changed files with 49 additions and 4 deletions

View File

@@ -0,0 +1,28 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd">
<StackLayout>
<GridLayout height="60" rows="auto" columns="auto, *">
<SearchBar id="searchBar1" hint="Search" text="auto(sb), * col, no width" />
</GridLayout>
<GridLayout height="60" rows="auto" columns="auto, *">
<SearchBar id="searchBar2" width="100%" hint="Search" text="auto(sb), * col, width 100%" />
</GridLayout>
<GridLayout height="60" rows="auto" columns="auto, *">
<SearchBar id="searchBar3" width="300" hint="Search" text="auto(sb), * col, width 300dip" />
</GridLayout>
<GridLayout height="60" rows="auto" columns="*, auto">
<SearchBar col="1" id="searchBar4" width="300" hint="Search" text="*, auto(sb) col, width 300dip" />
</GridLayout>
<GridLayout height="60" rows="auto" columns="auto, 200">
<SearchBar id="searchBar5" hint="Search" text="auto(sb), 200 cols, no width" />
</GridLayout>
<GridLayout height="60" rows="auto" columns="200, auto">
<SearchBar col="1" id="searchBar6" hint="Search" text="200, auto(sb) cols, no width" />
</GridLayout>
<StackLayout height="60">
<SearchBar id="searchBar7" hint="Search" text="stack, no width" />
</StackLayout>
<StackLayout height="60">
<SearchBar id="searchBar8" width="300" hint="Search" text="stack, width 300dip" />
</StackLayout>
</StackLayout>
</Page>

View File

@@ -11,8 +11,10 @@ export function pageLoaded(args: EventData) {
export function loadExamples() {
const examples = new Map<string, string>();
examples.set("issue-4147", "search-bar/issue-4147");
examples.set("search-bar", "search-bar/search-bar");
examples.set("issue-5039","search-bar/issue-5039");
examples.set("issue-4147", "search-bar/issue-4147");
examples.set("search-bar", "search-bar/search-bar");
examples.set("issue-5039", "search-bar/issue-5039");
examples.set("issue-5655", "search-bar/issue-5655");
return examples;
}

View File

@@ -3,9 +3,12 @@ import {
SearchBarBase, Color, colorProperty, backgroundColorProperty, backgroundInternalProperty, fontInternalProperty,
textProperty, hintProperty, textFieldHintColorProperty, textFieldBackgroundColorProperty
} from "./search-bar-common";
import { ios as iosUtils } from "../../utils/utils";
export * from "./search-bar-common";
const majorVersion = iosUtils.MajorVersion;
class UISearchBarDelegateImpl extends NSObject implements UISearchBarDelegate {
public static ObjCProtocols = [UISearchBarDelegate];
@@ -52,6 +55,18 @@ class UISearchBarDelegateImpl extends NSObject implements UISearchBarDelegate {
}
}
class UISearchBarImpl extends UISearchBar {
sizeThatFits(size: CGSize): CGSize {
// iOS11 SDK does not support passing sizeThatFits(...) non-finite width value;
// iOS layout system will take care to size the element properly when passed 0
if (majorVersion >= 11 && size.width === Number.POSITIVE_INFINITY) {
size.width = 0;
}
return super.sizeThatFits(size);
}
}
export class SearchBar extends SearchBarBase {
private _ios: UISearchBar;
private _delegate;
@@ -61,7 +76,7 @@ export class SearchBar extends SearchBarBase {
constructor() {
super();
this.nativeViewProtected = this._ios = UISearchBar.new();
this.nativeViewProtected = this._ios = UISearchBarImpl.new();
this._delegate = UISearchBarDelegateImpl.initWithOwner(new WeakRef(this));
}