Skip to content

Commit

Permalink
Merge pull request #11 from Softeq/feature/hide-all-toasts
Browse files Browse the repository at this point in the history
Added methods for clearing all toasts
  • Loading branch information
dimysa authored May 1, 2024
2 parents 5b9cdd7 + 0ac93ea commit 77b116d
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 7 deletions.
39 changes: 32 additions & 7 deletions samples/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22504"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -20,38 +19,64 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ulO-pt-Awz">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ulO-pt-Awz">
<rect key="frame" x="0.0" y="100" width="375" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="52Z-4q-3kU"/>
</constraints>
<state key="normal" title="Basic usage"/>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JYx-0k-Dz1">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JYx-0k-Dz1">
<rect key="frame" x="0.0" y="138" width="375" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="LUL-9G-oiK"/>
</constraints>
<state key="normal" title="Make with duration"/>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="UhU-8c-F0m" userLabel="Hide Toast">
<rect key="frame" x="112.5" y="176" width="75" height="35"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" title="Hide Toasts"/>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="mhs-jY-F3O" userLabel="Clear Queue">
<rect key="frame" x="187.5" y="176" width="75" height="35"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" title="Clear Queue"/>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="6KJ-0o-GoE" userLabel="Hide Toast And Clear Queue">
<rect key="frame" x="0.0" y="219" width="375" height="35"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" title="Hide Toasts And Clear Queue"/>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="JYx-0k-Dz1" secondAttribute="trailing" id="1tF-6H-Dqg"/>
<constraint firstItem="mhs-jY-F3O" firstAttribute="top" secondItem="JYx-0k-Dz1" secondAttribute="bottom" constant="8" id="2cT-xS-Odr"/>
<constraint firstItem="6KJ-0o-GoE" firstAttribute="leading" secondItem="JYx-0k-Dz1" secondAttribute="leading" id="4yi-Ka-CRV"/>
<constraint firstItem="UhU-8c-F0m" firstAttribute="top" secondItem="JYx-0k-Dz1" secondAttribute="bottom" constant="8" id="5vX-WS-Pdr"/>
<constraint firstItem="mhs-jY-F3O" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="ARQ-W1-fbJ"/>
<constraint firstItem="ulO-pt-Awz" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="BxJ-Ka-IMi"/>
<constraint firstItem="6KJ-0o-GoE" firstAttribute="top" secondItem="mhs-jY-F3O" secondAttribute="bottom" constant="8" id="YWQ-sN-cAQ"/>
<constraint firstAttribute="trailing" secondItem="ulO-pt-Awz" secondAttribute="trailing" id="ZLc-TP-SRw"/>
<constraint firstItem="UhU-8c-F0m" firstAttribute="trailing" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="jmg-Iq-fez"/>
<constraint firstItem="6KJ-0o-GoE" firstAttribute="trailing" secondItem="JYx-0k-Dz1" secondAttribute="trailing" id="mO7-CL-wle"/>
<constraint firstItem="JYx-0k-Dz1" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="nIp-jj-R8g"/>
<constraint firstItem="ulO-pt-Awz" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="80" id="rP9-xa-MIr"/>
<constraint firstItem="JYx-0k-Dz1" firstAttribute="top" secondItem="ulO-pt-Awz" secondAttribute="bottom" constant="8" id="sjY-qf-oke"/>
</constraints>
</view>
<connections>
<outlet property="BasicUsageBtn" destination="ulO-pt-Awz" id="GwC-0i-FqH"/>
<outlet property="ClearQueueBtn" destination="mhs-jY-F3O" id="Yay-2e-QLY"/>
<outlet property="HideToastsAndClearQueueBtn" destination="6KJ-0o-GoE" id="YGR-a5-W1h"/>
<outlet property="HideToastsBtn" destination="UhU-8c-F0m" id="cKa-ar-t2L"/>
<outlet property="MakeWithDurationBtn" destination="JYx-0k-Dz1" id="LTc-VC-dCQ"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-41" y="-69"/>
</scene>
</scenes>
</document>
6 changes: 6 additions & 0 deletions samples/ToastSamples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@
<ItemGroup>
<ProjectReference Include="..\src\ToastBindings.csproj" />
</ItemGroup>
<!-- Temporary solution for net6.0 https://github.com/dotnet/maui/discussions/15540#discussioncomment-6554443 -->
<!-- Can be removed after updating to net8.0 https://github.com/xamarin/xamarin-macios/issues/18964 -->
<PropertyGroup>
<MtouchLink>SdkOnly</MtouchLink>
<MtouchExtraArgs>$(MtouchExtraArgs) --weak-framework=NewsstandKit</MtouchExtraArgs>
</PropertyGroup>
</Project>
20 changes: 20 additions & 0 deletions samples/ViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,28 @@ public override void ViewDidLoad()
{
base.ViewDidLoad();

CSToastManager.SetQueueEnabled(true);

BasicUsageBtn.TouchUpInside += (sender, e) => MakeBasic();
MakeWithDurationBtn.TouchUpInside += (sender, e) => MakeWithDurationAndPosition();
HideToastsBtn.TouchUpInside += (s, e) => HideAllToast();
HideToastsAndClearQueueBtn.TouchUpInside += (s, e) => HideToastAndClearQueue();
ClearQueueBtn.TouchUpInside += (s, e) => ClearQueue();
}

private void ClearQueue()
{
ToastService.ClearToastQueue(View!);
}

private void HideToastAndClearQueue()
{
ToastService.HideAllToasts(View!);
}

private void HideAllToast()
{
ToastService.HideAllToasts(View!, false);
}

private void MakeBasic()
Expand Down
24 changes: 24 additions & 0 deletions samples/ViewController.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/ApiDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ void ShowToast(

[Export("hideToast:")]
void HideToast(UIView view);

[Export("hideAllToasts")]
void HideAllToasts();

[Export("hideAllToasts:clearQueue:")]
void HideAllToasts(bool includeActivity, bool clearQueue);

[Export("clearToastQueue")]
void ClearToastQueue();
}

[BaseType(typeof(NSObject))]
Expand Down
15 changes: 15 additions & 0 deletions src/ToastService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ public static void HideToast(UIView view, UIView toast)
view.HideToast(toast);
}

public static void HideAllToasts(UIView view)
{
view.HideAllToasts();
}

public static void HideAllToasts(UIView view, bool clearQueue)
{
view.HideAllToasts(false, clearQueue);
}

public static void ClearToastQueue(UIView view)
{
view.ClearToastQueue();
}

public static void ShowToast(UIView parentView,
UIView toastView,
ToastPosition? toastPosition = null,
Expand Down

0 comments on commit 77b116d

Please sign in to comment.