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

fix(ios-searchbar): fix crash with auto-sized searchbar in iOS11 Fixes #5655 by manoldonev · Pull Request #5658 · NativeScript/NativeScript · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (2) .xml  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
28 changes: 28 additions & 0 deletions apps/app/ui-tests-app/search-bar/issue-5655.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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>
8 changes: 5 additions & 3 deletions apps/app/ui-tests-app/search-bar/main-page.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
17 changes: 16 additions & 1 deletion tns-core-modules/ui/search-bar/search-bar.ios.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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;
Expand All @@ -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));
}

Expand Down

Back | FazBrowse Home | New Git URL