FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(ios-searchbar): fix searchbar auto sizing in iOS11 · NativeScript/NativeScript@0197ee1 · GitHub

Commit 0197ee1

Browse files
committed
fix(ios-searchbar): fix searchbar auto sizing in iOS11
1 parent 9717bbf commit 0197ee1

3 files changed

Lines changed: 51 additions & 4 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Page xmlns="http://schemas.nativescript.org/tns.xsd">
2+
<StackLayout>
3+
<GridLayout height="60" rows="auto" columns="auto, *">
4+
<SearchBar backgroundColor="red" id="searchBar1" hint="Search" text="auto(sb), * col, no width" />
5+
</GridLayout>
6+
<GridLayout height="60" rows="auto" columns="auto, *">
7+
<SearchBar backgroundColor="green" id="searchBar2" width="100%" hint="Search" text="auto(sb), * col, width 100%" />
8+
</GridLayout>
9+
<GridLayout height="60" rows="auto" columns="auto, *">
10+
<SearchBar backgroundColor="blue" id="searchBar3" width="300" hint="Search" text="auto(sb), * col, width 300dip" />
11+
</GridLayout>
12+
<GridLayout height="60" rows="auto" columns="*, auto">
13+
<SearchBar col="1" backgroundColor="blue" id="searchBar4" width="300" hint="Search" text="*, auto(sb) col, width 300dip" />
14+
</GridLayout>
15+
<GridLayout height="60" rows="auto" columns="auto, 200">
16+
<SearchBar backgroundColor="cyan" id="searchBar5" hint="Search" text="auto(sb), 200 cols, no width" />
17+
</GridLayout>
18+
<GridLayout height="60" rows="auto" columns="200, auto">
19+
<SearchBar backgroundColor="magenta" col="1" id="searchBar6" hint="Search" text="200, auto(sb) cols, no width" />
20+
</GridLayout>
21+
<StackLayout height="60">
22+
<SearchBar backgroundColor="yellow" id="searchBar7" hint="Search" text="stack, no width" />
23+
</StackLayout>
24+
<StackLayout height="60">
25+
<SearchBar backgroundColor="yellow" id="searchBar8" width="300" hint="Search" text="stack, width 300dip" />
26+
</StackLayout>
27+
</StackLayout>
28+
</Page>

‎apps/app/ui-tests-app/search-bar/main-page.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ export function pageLoaded(args: EventData) {
1111

1212
export function loadExamples() {
1313
const examples = new Map<string, string>();
14-
examples.set("issue-4147", "search-bar/issue-4147");
15-
examples.set("search-bar", "search-bar/search-bar");
16-
examples.set("issue-5039","search-bar/issue-5039");
14+
examples.set("issue-4147", "search-bar/issue-4147");
15+
examples.set("search-bar", "search-bar/search-bar");
16+
examples.set("issue-5039", "search-bar/issue-5039");
17+
examples.set("issue-5655", "search-bar/issue-5655");
18+
1719
return examples;
1820
}

‎tns-core-modules/ui/search-bar/search-bar.ios.ts‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ import {
33
SearchBarBase, Color, colorProperty, backgroundColorProperty, backgroundInternalProperty, fontInternalProperty,
44
textProperty, hintProperty, textFieldHintColorProperty, textFieldBackgroundColorProperty
55
} from "./search-bar-common";
6+
import { ios as iosUtils } from "../../utils/utils";
67

78
export * from "./search-bar-common";
89

10+
const majorVersion = iosUtils.MajorVersion;
11+
912
class UISearchBarDelegateImpl extends NSObject implements UISearchBarDelegate {
1013
public static ObjCProtocols = [UISearchBarDelegate];
1114

@@ -52,6 +55,20 @@ class UISearchBarDelegateImpl extends NSObject implements UISearchBarDelegate {
5255
}
5356
}
5457

58+
class UISearchBarImpl extends UISearchBar {
59+
sizeThatFits(size: CGSize): CGSize {
60+
// iOS11 SDK does not support passing sizeThatFits(...) non-finite width value;
61+
// iOS layout system will take care to size the element properly when passed 0
62+
if (majorVersion >= 11) {
63+
if (!!size.width) {
64+
size.width = 0;
65+
}
66+
}
67+
68+
return super.sizeThatFits(size);
69+
}
70+
}
71+
5572
export class SearchBar extends SearchBarBase {
5673
private _ios: UISearchBar;
5774
private _delegate;
@@ -61,7 +78,7 @@ export class SearchBar extends SearchBarBase {
6178
constructor() {
6279
super();
6380

64-
this.nativeViewProtected = this._ios = UISearchBar.new();
81+
this.nativeViewProtected = this._ios = UISearchBarImpl.new();
6582
this._delegate = UISearchBarDelegateImpl.initWithOwner(new WeakRef(this));
6683
}
6784

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL