mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(ios-searchbar): fix searchbar auto sizing in iOS11 (#5658)
This commit is contained in:
28
apps/app/ui-tests-app/search-bar/issue-5655.xml
Normal file
28
apps/app/ui-tests-app/search-bar/issue-5655.xml
Normal 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>
|
||||||
@@ -13,6 +13,8 @@ export function loadExamples() {
|
|||||||
const examples = new Map<string, string>();
|
const examples = new Map<string, string>();
|
||||||
examples.set("issue-4147", "search-bar/issue-4147");
|
examples.set("issue-4147", "search-bar/issue-4147");
|
||||||
examples.set("search-bar", "search-bar/search-bar");
|
examples.set("search-bar", "search-bar/search-bar");
|
||||||
examples.set("issue-5039","search-bar/issue-5039");
|
examples.set("issue-5039", "search-bar/issue-5039");
|
||||||
|
examples.set("issue-5655", "search-bar/issue-5655");
|
||||||
|
|
||||||
return examples;
|
return examples;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,12 @@ import {
|
|||||||
SearchBarBase, Color, colorProperty, backgroundColorProperty, backgroundInternalProperty, fontInternalProperty,
|
SearchBarBase, Color, colorProperty, backgroundColorProperty, backgroundInternalProperty, fontInternalProperty,
|
||||||
textProperty, hintProperty, textFieldHintColorProperty, textFieldBackgroundColorProperty
|
textProperty, hintProperty, textFieldHintColorProperty, textFieldBackgroundColorProperty
|
||||||
} from "./search-bar-common";
|
} from "./search-bar-common";
|
||||||
|
import { ios as iosUtils } from "../../utils/utils";
|
||||||
|
|
||||||
export * from "./search-bar-common";
|
export * from "./search-bar-common";
|
||||||
|
|
||||||
|
const majorVersion = iosUtils.MajorVersion;
|
||||||
|
|
||||||
class UISearchBarDelegateImpl extends NSObject implements UISearchBarDelegate {
|
class UISearchBarDelegateImpl extends NSObject implements UISearchBarDelegate {
|
||||||
public static ObjCProtocols = [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 {
|
export class SearchBar extends SearchBarBase {
|
||||||
private _ios: UISearchBar;
|
private _ios: UISearchBar;
|
||||||
private _delegate;
|
private _delegate;
|
||||||
@@ -61,7 +76,7 @@ export class SearchBar extends SearchBarBase {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.nativeViewProtected = this._ios = UISearchBar.new();
|
this.nativeViewProtected = this._ios = UISearchBarImpl.new();
|
||||||
this._delegate = UISearchBarDelegateImpl.initWithOwner(new WeakRef(this));
|
this._delegate = UISearchBarDelegateImpl.initWithOwner(new WeakRef(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user