Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RootElement and Radio fixes and improvements. #253

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a8bbed2
Searchable RootElements. Fixes for Radio.
toxsedyshev Aug 21, 2020
0a56ab1
Unify fonts for different elements.
toxsedyshev Aug 21, 2020
e141251
Searchable RootElement example.
toxsedyshev Aug 21, 2020
63a85b4
Modal Dialog example.
toxsedyshev Aug 21, 2020
5140fe6
StringElement Value Summary fix.
toxsedyshev Sep 2, 2020
6b2fbd6
StyledStringElement and StyledMultilineElement GetHeight fixes.
toxsedyshev Sep 2, 2020
eacaeb8
Demo update.
toxsedyshev Sep 2, 2020
6255a5d
RootElement Value for Summary
toxsedyshev Sep 21, 2020
d775c8a
StyledStringElement Image centering.
toxsedyshev Sep 29, 2020
477de33
Demo updated.
toxsedyshev Sep 29, 2020
91f2699
Section insert items fix.
toxsedyshev Oct 8, 2020
c48d373
StyledStringElement Image centering cell reuse fix.
toxsedyshev Oct 21, 2020
cb895db
RadioGroup NotSelectedCaption added.
toxsedyshev May 18, 2021
fbb2be7
Update .gitignore
toxsedyshev Dec 30, 2021
384553b
Show space char in the end of right aligned entry input.
toxsedyshev Jan 13, 2022
ece97d6
DialogViewController.Title customization.
toxsedyshev Feb 21, 2022
52d5e96
Radio RootElement SearchBar customization.
toxsedyshev Feb 21, 2022
e3019f0
DialogViewController.Title customization.
toxsedyshev Feb 21, 2022
0f72f76
RadioElement index reload fix.
toxsedyshev Feb 21, 2022
943e6f6
PrepareDialogViewController callback.
toxsedyshev Feb 21, 2022
dcedf0d
EntryElement refactoring.
toxsedyshev Mar 9, 2022
f15e85e
HideKeyboardWithDoneButton added.
toxsedyshev Mar 27, 2022
8b64750
EntryElement OnChanged fix.
toxsedyshev Apr 12, 2022
0b993c8
SearchLabel fixes.
toxsedyshev Apr 27, 2022
23a26e6
RadioElement index reload fix.
toxsedyshev Apr 27, 2022
3052a5b
Searchable RootElements. Fixes for Radio.
toxsedyshev Jun 13, 2022
d65cf5c
RootElement Search refactoring.
toxsedyshev Jun 14, 2022
3acb37d
.gitignore updated.
toxsedyshev Jun 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
*~
*.userprefs
*.user
*.suo
*.pidb
.vs

.DS_Store
200 changes: 137 additions & 63 deletions MonoTouch.Dialog/DialogViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public bool EnableSearch {
public bool AutoHideSearch { get; set; }

public string SearchPlaceholder { get; set; }

public string SearchLabel { get; set; }

/// <summary>
/// Invoke this method to trigger a data refresh.
Expand Down Expand Up @@ -150,89 +152,100 @@ public override void DidRotate (UIInterfaceOrientation fromInterfaceOrientation)
ReloadData ();
}
#endif

Section [] originalSections;
Element [][] originalElements;


bool SearchFiltered;

/// <summary>
/// Allows caller to programatically activate the search bar and start the search process
/// </summary>
public void StartSearch ()
public void StartSearch()
{
if (originalSections != null)
if (SearchFiltered)
{
return;

}

#if !__TVOS__
searchBar.BecomeFirstResponder ();
searchBar.BecomeFirstResponder();
#endif
originalSections = Root.Sections.ToArray ();
originalElements = new Element [originalSections.Length][];
for (int i = 0; i < originalSections.Length; i++)
originalElements [i] = originalSections [i].Elements.ToArray ();
SearchFiltered = true;
}

/// <summary>
/// Allows the caller to programatically stop searching.
/// </summary>
public virtual void FinishSearch ()
public virtual void FinishSearch()
{
if (originalSections == null)
if (!SearchFiltered)
{
return;

Root.Sections = new List<Section> (originalSections);
originalSections = null;
originalElements = null;
}

Root.SectionsSearchFiltered = null;
SearchFiltered = false;
#if !__TVOS__
searchBar.ResignFirstResponder ();
searchBar.ResignFirstResponder();
#endif
ReloadData ();
ReloadData();
}
public delegate void SearchTextEventHandler (object sender, SearchChangedEventArgs args);

public delegate void SearchTextEventHandler(object sender, SearchChangedEventArgs args);
public event SearchTextEventHandler SearchTextChanged;
public virtual void OnSearchTextChanged (string text)

public virtual void OnSearchTextChanged(string text)
{
if (SearchTextChanged != null)
SearchTextChanged (this, new SearchChangedEventArgs (text));
}

public void PerformFilter (string text)
SearchTextChanged?.Invoke(this, new SearchChangedEventArgs(text));
}

public void PerformFilter(string text)
{
if (originalSections == null)
if (!SearchFiltered)
{
return;

OnSearchTextChanged (text);

var newSections = new List<Section> ();

for (int sidx = 0; sidx < originalSections.Length; sidx++){
}

OnSearchTextChanged(text);

if (string.IsNullOrWhiteSpace(text))
{
Root.SectionsSearchFiltered = null;
ReloadData();
return;
}

var newSections = new List<Section>();

foreach (var section in Root.SectionsOriginal)
{
Section newSection = null;
var section = originalSections [sidx];
Element [] elements = originalElements [sidx];

for (int eidx = 0; eidx < elements.Length; eidx++){
if (elements [eidx].Matches (text)){
if (newSection == null){
newSection = new Section (section.Header, section.Footer){

foreach (var element in section.Elements)
{
if (element.Matches(text))
{
if (newSection == null)
{
newSection = new Section(section.Header, section.Footer)
{
SearchFiltered = true,
FooterView = section.FooterView,
HeaderView = section.HeaderView
HeaderView = section.HeaderView,
Caption = section.Caption,
Parent = Root
};
newSections.Add (newSection);
newSections.Add(newSection);
}
newSection.Add (elements [eidx]);
newSection.Add(element, false);
}
}
}

Root.Sections = newSections;

ReloadData ();
}

public virtual void SearchButtonClicked (string text)
{

Root.SectionsSearchFiltered = newSections;

ReloadData();
}

public virtual void SearchButtonClicked(string text) { }

class SearchDelegate : UISearchBarDelegate {
DialogViewController container;
Expand All @@ -245,13 +258,17 @@ public SearchDelegate (DialogViewController container)
public override void OnEditingStarted (UISearchBar searchBar)
{
#if !__TVOS__
searchBar.ShowsCancelButton = true;
if (container.SearchLabel == null)
{
searchBar.ShowsCancelButton = true;
}
#endif
container.StartSearch ();
}

public override void OnEditingStopped (UISearchBar searchBar)
{
container.searchBar.Text = "";
#if !__TVOS__
searchBar.ShowsCancelButton = false;
#endif
Expand Down Expand Up @@ -473,8 +490,56 @@ void SetupSearch ()
Delegate = new SearchDelegate (this)
};
if (SearchPlaceholder != null)
searchBar.Placeholder = this.SearchPlaceholder;
tableView.TableHeaderView = searchBar;
{
searchBar.Placeholder = SearchPlaceholder;
}
if (SearchLabel != null)
{
UIView view = searchBar;
try
{
var root = searchBar.Subviews[0];
var parent = root.Subviews[1];
var field = (UISearchTextField)parent.Subviews[0];

var dy = 20;
var rf = root.Frame;
rf.Y = dy;
root.Frame = rf;

var font = UIFont.BoldSystemFontOfSize(17);
var f = parent.Frame;
var x1 = 20;
var x2 = 30;
var w = SearchLabel.StringSize(font).Width;
parent.Frame = new CGRect(f.X + w + x1 + x2, f.Y, f.Width - (w + x1 + x2), f.Height);

field.LeftView = null; // hides search icon
field.BackgroundColor = UIColor.White;
field.InputAccessoryView = EntryElement.GetHideKeyboardToolbar(tableView);
var ff = field.Frame;
ff.Width -= w + x1 + x2;
field.Frame = ff;

var label = new UILabel(new CGRect(f.X + x1, f.Y, w, f.Height))
{
Text = SearchLabel,
Font = font
};
root.Add(label);

var sf = searchBar.Frame;
sf.Height += dy;
view = new UIView(sf) { searchBar };
}
catch { }

tableView.TableHeaderView = view;
}
else
{
tableView.TableHeaderView = searchBar;
}
} else {
// Does not work with current Monotouch, will work with 3.0
// tableView.TableHeaderView = null;
Expand Down Expand Up @@ -552,8 +617,8 @@ public override void ViewWillAppear (bool animated)
#if !__TVOS__
NavigationItem.HidesBackButton = !pushing;
#endif
if (root.Caption != null)
NavigationItem.Title = root.Caption;
if (root.Title != null)
NavigationItem.Title = root.Title;
if (dirty){
tableView.ReloadData ();
dirty = false;
Expand All @@ -563,7 +628,16 @@ public override void ViewWillAppear (bool animated)
ViewAppearing (this, EventArgs.Empty);
}

public bool Pushing {
public event EventHandler ViewDoingLayoutSubviews;

public override void ViewDidLayoutSubviews()
{
base.ViewDidLayoutSubviews();

ViewDoingLayoutSubviews?.Invoke(this, EventArgs.Empty);
}

public bool Pushing {
get {
return pushing;
}
Expand Down Expand Up @@ -597,8 +671,8 @@ public void ReloadData ()
if (root == null)
return;

if(root.Caption != null)
NavigationItem.Title = root.Caption;
if(root.Title != null)
NavigationItem.Title = root.Title;

root.Prepare ();
if (tableView != null){
Expand Down
Loading