149 lines
5.1 KiB
C#
149 lines
5.1 KiB
C#
using MarketAlly.SpotlightTour.Maui;
|
|
|
|
namespace Test.SpotlightTour.Pages;
|
|
|
|
public partial class StepActionsPage : ContentPage
|
|
{
|
|
private readonly List<string> _actionLog = new();
|
|
|
|
public StepActionsPage()
|
|
{
|
|
InitializeComponent();
|
|
SetupStepActions();
|
|
}
|
|
|
|
private void SetupStepActions()
|
|
{
|
|
// Method 1: Register actions by StepKey (centralized approach)
|
|
TourHost.RegisterStepEnteringAction("settings-card", async (step, token) =>
|
|
{
|
|
LogAction("Entering settings-card: Switching to Settings tab...");
|
|
|
|
// Switch to Settings tab before spotlight appears
|
|
await MainThread.InvokeOnMainThreadAsync(() => SwitchToTab(1));
|
|
await Task.Delay(150); // Wait for UI to update
|
|
});
|
|
|
|
TourHost.RegisterStepEnteringAction("profile-card", async (step, token) =>
|
|
{
|
|
LogAction("Entering profile-card: Switching to Profile tab...");
|
|
|
|
// Switch to Profile tab
|
|
await MainThread.InvokeOnMainThreadAsync(() => SwitchToTab(2));
|
|
await Task.Delay(150);
|
|
});
|
|
|
|
// Method 2: Attach action directly to element via attached property
|
|
Onboarding.SetOnEntering(SettingsCard, async (step, token) =>
|
|
{
|
|
LogAction("OnEntering attached property executed for SettingsCard");
|
|
await Task.CompletedTask;
|
|
});
|
|
|
|
// Method 3: Use events for cross-cutting concerns
|
|
TourHost.StepEntering += async (sender, e) =>
|
|
{
|
|
LogAction($"StepEntering event: {e.Step.StepKey} (index {e.StepIndex})");
|
|
|
|
// Conditional skip: Skip premium step if toggle is on
|
|
if (e.Step.StepKey == "premium-feature" && SkipPremiumSwitch.IsToggled)
|
|
{
|
|
LogAction("Skipping premium-feature step (toggle is ON)");
|
|
e.Skip = true;
|
|
}
|
|
|
|
await Task.CompletedTask;
|
|
};
|
|
|
|
TourHost.StepEntered += (sender, e) =>
|
|
{
|
|
LogAction($"StepEntered event: {e.Step.StepKey} is now visible");
|
|
};
|
|
|
|
TourHost.StepLeaving += async (sender, e) =>
|
|
{
|
|
LogAction($"StepLeaving event: Leaving {e.Step.StepKey}");
|
|
|
|
// Example: Close side panel when leaving any step
|
|
if (SidePanel.IsVisible)
|
|
{
|
|
await MainThread.InvokeOnMainThreadAsync(() => SidePanel.IsVisible = false);
|
|
}
|
|
|
|
await Task.CompletedTask;
|
|
};
|
|
|
|
// Tour lifecycle events
|
|
TourHost.TourCompleted += (s, e) =>
|
|
{
|
|
LogAction("Tour completed!");
|
|
MainThread.BeginInvokeOnMainThread(() => SwitchToTab(0)); // Reset to Home
|
|
};
|
|
|
|
TourHost.TourSkipped += (s, e) =>
|
|
{
|
|
LogAction("Tour skipped");
|
|
MainThread.BeginInvokeOnMainThread(() => SwitchToTab(0)); // Reset to Home
|
|
};
|
|
}
|
|
|
|
private void SwitchToTab(int index)
|
|
{
|
|
// Get theme-aware colors
|
|
var isDark = Application.Current?.RequestedTheme == AppTheme.Dark;
|
|
var activeColor = Color.FromArgb("#512BD4"); // Primary
|
|
var inactiveColor = isDark ? Color.FromArgb("#3A3A3C") : Color.FromArgb("#E0E0E0");
|
|
var activeTextColor = Colors.White;
|
|
var inactiveTextColor = isDark ? Colors.White : Color.FromArgb("#333333");
|
|
|
|
// Update tab button styles
|
|
HomeTabBtn.BackgroundColor = index == 0 ? activeColor : inactiveColor;
|
|
HomeTabBtn.TextColor = index == 0 ? activeTextColor : inactiveTextColor;
|
|
|
|
SettingsTabBtn.BackgroundColor = index == 1 ? activeColor : inactiveColor;
|
|
SettingsTabBtn.TextColor = index == 1 ? activeTextColor : inactiveTextColor;
|
|
|
|
ProfileTabBtn.BackgroundColor = index == 2 ? activeColor : inactiveColor;
|
|
ProfileTabBtn.TextColor = index == 2 ? activeTextColor : inactiveTextColor;
|
|
|
|
// Show/hide content
|
|
HomeContent.IsVisible = index == 0;
|
|
SettingsContent.IsVisible = index == 1;
|
|
ProfileContent.IsVisible = index == 2;
|
|
}
|
|
|
|
private void LogAction(string message)
|
|
{
|
|
var timestamp = DateTime.Now.ToString("HH:mm:ss.fff");
|
|
_actionLog.Add($"[{timestamp}] {message}");
|
|
|
|
// Keep only last 5 entries
|
|
while (_actionLog.Count > 5)
|
|
_actionLog.RemoveAt(0);
|
|
|
|
MainThread.BeginInvokeOnMainThread(() =>
|
|
{
|
|
LogLabel.Text = string.Join("\n", _actionLog);
|
|
});
|
|
|
|
System.Diagnostics.Debug.WriteLine($"[StepActions] {message}");
|
|
}
|
|
|
|
private async void OnStartTourClicked(object? sender, EventArgs e)
|
|
{
|
|
_actionLog.Clear();
|
|
LogAction("Starting tour...");
|
|
|
|
// Reset to Home tab
|
|
SwitchToTab(0);
|
|
|
|
var result = await TourHost.StartTourAsync(this.Content);
|
|
LogAction($"Tour ended with result: {result}");
|
|
}
|
|
|
|
private void OnHomeTabClicked(object? sender, EventArgs e) => SwitchToTab(0);
|
|
private void OnSettingsTabClicked(object? sender, EventArgs e) => SwitchToTab(1);
|
|
private void OnProfileTabClicked(object? sender, EventArgs e) => SwitchToTab(2);
|
|
private void OnClosePanelClicked(object? sender, EventArgs e) => SidePanel.IsVisible = false;
|
|
}
|