Все представления TipKit не отображаются при нажатии кнопкиIOS

Программируем под IOS
Ответить
Anonymous
 Все представления TipKit не отображаются при нажатии кнопки

Сообщение Anonymous »

У меня есть 4 подсказки, которые нужно отобразить на экране, поэтому я создал такой
код:
struct TipContent {
let title: String
let message: String
}

// MARK: - TipKit Manager
class TipKitManager: ObservableObject {
static let shared = TipKitManager()

// All tip contents in a single array
let tipContents: [TipContent] = [
TipContent(title: "Welcome!", message: "Start your journey by logging in to your account."),
TipContent(title: "Enter Username!", message: "Provide your username or email to proceed."),
TipContent(title: "Enter Password!", message: "Use your secure password to log in safely."),
TipContent(title: "Register!", message: "Don't have an account? Tap Register to create one!")
]

@Published var currentTipIndex: Int = 0
@Published var showTip: Bool = true

var currentTip: LoginTip? {
guard showTip && currentTipIndex < tipContents.count else { return nil }
return LoginTip(index: currentTipIndex, content: tipContents[currentTipIndex])
}

var totalSteps: Int {
tipContents.count
}

var currentStep: Int {
currentTipIndex + 1
}

func moveToNextTip() {
if currentTipIndex < tipContents.count - 1 {
currentTip?.invalidate(reason: .tipClosed)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.currentTipIndex += 1
}
} else {
dismissTips()
}
}

func dismissTips() {
currentTip?.invalidate(reason: .tipClosed)
showTip = false
}

func resetTips() {
currentTipIndex = 0
showTip = true
}
}

// MARK: - Dynamic Tip
struct LoginTip: Tip {
let index: Int
let content: TipContent

var title: Text {
Text(content.title)
}

var message: Text? {
Text(content.message)
}
}

// MARK: - Custom Tip View Style (Refactored)
struct NewFeatureTipViewStyle: TipViewStyle {
let step: Int
let totalSteps: Int
var onNext: (() -> Void)? = nil

func makeBody(configuration: Configuration) -> some View {
VStack(alignment: .leading, spacing: 10) {
configuration.title
.font(.title2)
.bold()

configuration.message
.foregroundStyle(.secondary)

HStack {
// Progress dots
HStack {
ForEach(1...totalSteps, id: \.self) { i in
Capsule()
.fill(i == step ? .green : .gray.opacity(0.4))
.frame(width: 24, height: 6)
}
}

Spacer()

if step < totalSteps {
Button("Next") { onNext?() }
.foregroundStyle(.green)
} else {
Button("Done") {
configuration.tip.invalidate(reason: .tipClosed)
}
.foregroundStyle(.green)
}
}
.padding(.top, 10)
}
.padding(.vertical, 20)
.padding(.horizontal, 24)
}
}

Экран входа в систему: здесь я показываю подсказки, но сначала отображается 1-й вид подсказки, но здесь, если я нажму «Далее», он должен переместиться на 2-е место (текстовое поле электронной почты), но он закрывается.. не переходит на 2-е и все 4... где я ошибаюсь.. как исправить
struct LoginView: View {

@StateObject private var tipManager = TipKitManager.shared

var body: some View {

VStack(spacing: 30) {

// MARK: LOGIN HEADER
Text("Login")

.popoverTip(tipManager.currentTipIndex == 0 ? tipManager.currentTip : nil, arrowEdge: .top)
.tipViewStyle(
NewFeatureTipViewStyle(
step: tipManager.currentStep,
totalSteps: tipManager.totalSteps,
onNext: { tipManager.moveToNextTip() }
)
)

VStack(spacing: 20) {
// MARK: USERNAME
TextField("Enter email or username", text: $userName)
.textFieldStyle(.roundedBorder)
.popoverTip(tipManager.currentTipIndex == 1 ? tipManager.currentTip : nil, arrowEdge: .bottom)
.tipViewStyle(
NewFeatureTipViewStyle(
step: tipManager.currentStep,
totalSteps: tipManager.totalSteps,
onNext: { tipManager.moveToNextTip() }
)
)

// MARK: PASSWORD
SecureField("Password", text: $uaerPassword)
.textFieldStyle(.roundedBorder)
.popoverTip(tipManager.currentTipIndex == 2 ? tipManager.currentTip : nil, arrowEdge: .bottom)
.tipViewStyle(
NewFeatureTipViewStyle(
step: tipManager.currentStep,
totalSteps: tipManager.totalSteps,
onNext: { tipManager.moveToNextTip() }
)
)

// MARK: REGISTER
HStack {
Text("Don't have an account?")
.foregroundColor(.gray)

Text("Register here!")

.popoverTip(tipManager.currentTipIndex == 3 ? tipManager.currentTip : nil, arrowEdge: .top)
.tipViewStyle(
NewFeatureTipViewStyle(
step: tipManager.currentStep,
totalSteps: tipManager.totalSteps,
onNext: { tipManager.moveToNextTip() }
)
)
.onTapGesture {
isRegTapped = true
}
}
}
.padding()

Spacer()
}

}

}


Подробнее здесь: https://stackoverflow.com/questions/798 ... ton-action
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»