Skip to content

Commit

Permalink
Attach And Run iOS / catalyst (#19571)
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen committed Jan 2, 2024
1 parent 3944004 commit 61ca414
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,15 @@ public async virtual Task SettingSemanticDescriptionMakesElementAccessible()
{
var view = new TStub();
MockAccessibilityExpectations(view);

view.Semantics.Description = "Test";
var important = await GetValueAsync(view, handler => view.IsAccessibilityElement());

#if IOS || MACCATALYST
bool attachAndRun = true;
#else
bool attachAndRun = false;
#endif

var important = await GetValueAsync(view, handler => view.IsAccessibilityElement(), attachAndRun);

Assert.True(important);
}
Expand All @@ -96,8 +102,14 @@ public async virtual Task SettingSemanticHintMakesElementAccessible()
var view = new TStub();
MockAccessibilityExpectations(view);

#if IOS || MACCATALYST
bool attachAndRun = true;
#else
bool attachAndRun = false;
#endif

view.Semantics.Hint = "Test";
var important = await GetValueAsync(view, handler => view.IsAccessibilityElement());
var important = await GetValueAsync(view, handler => view.IsAccessibilityElement(), attachAndRun);

Assert.True(important);
}
Expand Down Expand Up @@ -134,7 +146,13 @@ public async Task SetSemanticHeading()
var view = new TStub();
view.Semantics.HeadingLevel = SemanticHeadingLevel.Level1;

var id = await GetValueAsync(view, handler => GetSemanticHeading(handler));
#if IOS || MACCATALYST
bool attachAndRun = true;
#else
bool attachAndRun = false;
#endif

var id = await GetValueAsync(view, handler => GetSemanticHeading(handler), attachAndRun);
Assert.Equal(view.Semantics.HeadingLevel, id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,19 @@ protected Task<THandler> CreateHandlerAsync(IView view)
});
}

protected Task<TValue> GetValueAsync<TValue>(IView view, Func<THandler, TValue> func)
protected Task<TValue> GetValueAsync<TValue>(IView view, Func<THandler, TValue> func, bool attachAndRun = false)
{
return InvokeOnMainThreadAsync(() =>
return InvokeOnMainThreadAsync<TValue>(() =>
{
var handler = CreateHandler(view);
return func(handler);
if (attachAndRun)
{
return AttachAndRun(view, func);
}
else
{
THandler handler = CreateHandler(view);
return Task.FromResult(func(handler));
}
});
}

Expand Down

0 comments on commit 61ca414

Please sign in to comment.