-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(GiniBankSDKExample): Implemented Demo screen in SwiftUI <3
- Loading branch information
1 parent
a0e889e
commit 5051d1a
Showing
8 changed files
with
250 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
BankSDK/GiniBankSDKExample/GiniBankSDKExample/DemoScreen/SwiftUI/DemoScreenSwiftUIView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import SwiftUI | ||
import GiniCaptureSDK | ||
import GiniBankSDK | ||
|
||
struct DemoView: View { | ||
@State private var ibanText: String = "" | ||
var clientId: String? | ||
var onPhotoPayment: () -> Void | ||
var onSettingsTap: () -> Void | ||
var onEntryPointSelected: (GiniConfiguration.GiniEntryPoint) -> Void | ||
|
||
var body: some View { | ||
VStack { | ||
Spacer(minLength: Constants.giniLogoTopConstant) | ||
|
||
// Gini Logo | ||
Image("gini_logo") | ||
.resizable() | ||
.scaledToFit() | ||
.frame(width: 114, height: 72) | ||
|
||
// Welcome Title | ||
Text(DemoScreenStrings.welcomeTitle.localized) | ||
.font(.system(size: 22, weight: .bold)) | ||
.padding(.top, Constants.welcomeTitleTopConstant) | ||
|
||
// Description Text | ||
Text(DemoScreenStrings.screenDescription.localized) | ||
.font(.system(size: 17)) | ||
.multilineTextAlignment(.center) | ||
.lineLimit(nil) | ||
.fixedSize(horizontal: false, vertical: true) | ||
.padding(.horizontal, 50) | ||
.padding(.top, 12) | ||
|
||
VStack(spacing: 24) { | ||
IBANTextFieldSwiftUIView(ibanText: $ibanText, onCameraTap: { | ||
onEntryPointSelected(.field) | ||
}) | ||
.padding(.horizontal, Constants.stackViewMarginConstant) | ||
|
||
Text(DemoScreenStrings.alternativeText.localized) | ||
.font(.system(size: 15)) | ||
.multilineTextAlignment(.center) | ||
|
||
GiniSwiftUIButton(title: DemoScreenStrings.photoPaymentButtonTitle.localized, | ||
action: { | ||
onEntryPointSelected(.button) | ||
}) | ||
.frame(maxWidth: .infinity, minHeight: 44) | ||
.background(Color(Constants.itemBackgroundColor)) | ||
.cornerRadius(7) | ||
.padding(.horizontal, Constants.stackViewMarginConstant) | ||
} | ||
.padding(.top, Constants.stackViewTopConstant) | ||
|
||
|
||
Spacer() | ||
|
||
// Meta Information | ||
Text("Gini Bank SDK: (\(GiniBankSDKVersion)) / Gini Capture SDK: (\(GiniCaptureSDKVersion)) / Client id: \(clientId ?? "")") | ||
.font(.system(size: 11)) | ||
.multilineTextAlignment(.center) | ||
.lineLimit(nil) // Ensures unlimited lines (equivalent to numberOfLines = 0) | ||
.fixedSize(horizontal: false, vertical: true) // Allows text to expand vertically | ||
.padding(.horizontal, 50) | ||
.padding(.bottom, 14) | ||
.onTapGesture { | ||
onSettingsTap() | ||
} | ||
} | ||
.background(Color(UIColor.systemBackground)) | ||
.onTapGesture { | ||
hideKeyboard() | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Constants | ||
private struct Constants { | ||
static let welcomeTitleTopConstant: CGFloat = Device.small ? 24 : UIDevice.current.isIpad ? 85 : 48 | ||
static let giniLogoTopConstant: CGFloat = Device.small ? 48 : UIDevice.current.isIpad ? 150 : 112 | ||
static let stackViewTopConstant: CGFloat = 72 | ||
static let stackViewMarginConstant: CGFloat = UIDevice.current.isIpad ? 64 : 16 | ||
static let itemBackgroundColor = GiniColor( | ||
light: giniCaptureColor("Light04"), | ||
dark: giniCaptureColor("Dark04") | ||
).uiColor() | ||
} | ||
|
||
// MARK: - Hide Keyboard Helper | ||
extension View { | ||
func hideKeyboard() { | ||
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) | ||
} | ||
} | ||
|
||
// MARK: - Preview | ||
#Preview { | ||
DemoView(clientId: "example-client-id", | ||
onPhotoPayment: {}, | ||
onSettingsTap: {}, | ||
onEntryPointSelected: { _ in }) | ||
} |
34 changes: 34 additions & 0 deletions
34
BankSDK/GiniBankSDKExample/GiniBankSDKExample/DemoScreen/SwiftUI/GiniSwiftUIButton.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// GiniSwiftUIButton.swift | ||
// | ||
// Copyright © 2025 Gini GmbH. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import GiniCaptureSDK | ||
|
||
struct GiniSwiftUIButton: View { | ||
let title: String | ||
let action: () -> Void | ||
|
||
var body: some View { | ||
Button(action: action) { | ||
Text(title) | ||
.font(.system(size: 17, weight: .semibold)) | ||
.frame(maxWidth: .infinity) | ||
.foregroundColor(Color(Constants.textColor)) | ||
.padding() | ||
} | ||
.background(Color(Constants.itemBackgroundColor)) | ||
.cornerRadius(7) | ||
} | ||
} | ||
|
||
private struct Constants { | ||
static let textColor = GiniColor(light: .black, dark: .white).uiColor() | ||
static let iconColor = GiniColor(light: .black, dark: .white).uiColor() | ||
static let itemBackgroundColor = GiniColor( | ||
light: giniCaptureColor("Light04"), | ||
dark: giniCaptureColor("Dark04") | ||
).uiColor() | ||
} |
38 changes: 38 additions & 0 deletions
38
...K/GiniBankSDKExample/GiniBankSDKExample/DemoScreen/SwiftUI/IBANTextFieldSwiftUIView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// IBANTextFieldSwiftUIView.swift | ||
// | ||
// Copyright © 2025 Gini GmbH. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import GiniCaptureSDK | ||
|
||
struct IBANTextFieldSwiftUIView: View { | ||
@Binding var ibanText: String | ||
var onCameraTap: () -> Void | ||
|
||
var body: some View { | ||
HStack { | ||
// IBAN TextField | ||
TextField(DemoScreenStrings.ibanTextFieldPlaceholder.localized, text: $ibanText) | ||
.font(.system(size: 17)) | ||
.padding(.leading, 16) | ||
.foregroundColor(.black) | ||
.frame(height: 50) // Adjust height to match design | ||
.background(Color.clear) | ||
|
||
// Camera Icon Button | ||
Button(action: onCameraTap) { | ||
Image(systemName: "camera") | ||
.resizable() | ||
.scaledToFit() | ||
.frame(width: 24, height: 24) | ||
.foregroundColor(.black) | ||
.padding(.trailing, 16) | ||
} | ||
} | ||
.frame(height: 50) // Match the height | ||
.background(Color(UIColor.systemGray6)) // Use a light background color | ||
.cornerRadius(10) // Rounded corners | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.