Skip to content

Commit f7e07c8

Browse files
committed
Use TipKit instead of custom TipView
1 parent 159de5c commit f7e07c8

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed

firebaseai/FirebaseAIExample/Features/Live/Screens/LiveScreen.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import FirebaseAI
1919
#endif
2020
import SwiftUI
21+
import TipKit
2122

2223
struct LiveScreen: View {
2324
let backendType: BackendOption
@@ -40,7 +41,7 @@ struct LiveScreen: View {
4041
ErrorDetailsView(error: error)
4142
}
4243
if let tip = viewModel.tip, !viewModel.hasTranscripts {
43-
TipView(text: tip)
44+
TipView(tip)
4445
}
4546
ConnectButton(
4647
state: viewModel.state,

firebaseai/FirebaseAIExample/Features/Live/ViewModels/LiveViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class LiveViewModel: ObservableObject {
4949
var title: String
5050

5151
@Published
52-
var tip: String?
52+
var tip: InlineTip?
5353

5454
@Published
5555
var isAudioOutputEnabled: Bool = {

firebaseai/FirebaseAIExample/FirebaseAIExampleApp.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import FirebaseCore
1616
import SwiftUI
17+
import TipKit
1718

1819
class AppDelegate: NSObject, UIApplicationDelegate {
1920
func application(_ application: UIApplication,
@@ -41,6 +42,14 @@ class AppDelegate: NSObject, UIApplicationDelegate {
4142
struct FirebaseAIExampleApp: App {
4243
@UIApplicationDelegateAdaptor var appDelegate: AppDelegate
4344

45+
init() {
46+
do {
47+
try Tips.configure()
48+
} catch {
49+
print("Error initializing tips: \(error)")
50+
}
51+
}
52+
4453
var body: some Scene {
4554
WindowGroup {
4655
ContentView()

firebaseai/FirebaseAIExample/Shared/Models/Sample.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public struct Sample: Identifiable {
3333
public let generationConfig: GenerationConfig?
3434
public let liveGenerationConfig: LiveGenerationConfig?
3535
public let fileDataParts: [FileDataPart]?
36-
public let tip: String?
36+
public let tip: InlineTip?
3737

3838
public init(title: String,
3939
description: String,
@@ -47,7 +47,7 @@ public struct Sample: Identifiable {
4747
generationConfig: GenerationConfig? = nil,
4848
liveGenerationConfig: LiveGenerationConfig? = nil,
4949
fileDataParts: [FileDataPart]? = nil,
50-
tip: String? = nil) {
50+
tip: InlineTip? = nil) {
5151
self.title = title
5252
self.description = description
5353
self.useCases = useCases
@@ -307,7 +307,7 @@ extension Sample {
307307
speech: SpeechConfig(voiceName: "Zephyr", languageCode: "en-US"),
308308
outputAudioTranscription: AudioTranscriptionConfig()
309309
),
310-
tip: "Try asking the model to change the background color",
310+
tip: InlineTip(text: "Try asking the model to change the background color"),
311311
),
312312
]
313313

firebaseai/FirebaseAIExample/Shared/Views/TipView.swift renamed to firebaseai/FirebaseAIExample/Shared/Views/InlineTip.swift

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,32 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import SwiftUI
15+
import TipKit
1616

17-
struct TipView: View {
18-
let text: String
17+
public struct InlineTip: Tip {
18+
private let _text: String
19+
private let _title: String
20+
private let _icon: Image
1921

20-
var body: some View {
21-
VStack(alignment: .leading, spacing: 5) {
22-
Label("Tip", systemImage: "info.circle")
23-
.bold()
24-
.foregroundStyle(Color.accentColor)
25-
Text(text)
26-
.font(.caption)
27-
.italic()
28-
}
22+
public init(text: String, title: String = "Tip", icon: Image = Image(systemName: "info.circle")) {
23+
_text = text
24+
_title = title
25+
_icon = icon
26+
}
27+
28+
public var title: Text {
29+
Text(_title)
30+
}
31+
32+
public var message: Text? {
33+
Text(_text)
34+
}
35+
36+
public var image: Image? {
37+
_icon
2938
}
3039
}
3140

3241
#Preview {
33-
TipView(text: "Try asking the model to change the background color")
42+
//TipView(text: "Try asking the model to change the background color")
3443
}

0 commit comments

Comments
 (0)