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
var body: some View { | |
VStack { | |
// Generate form UI | |
Form { | |
// Generate section UI | |
Section { | |
TextField("Your email address*", text: $email) | |
.keyboardType(.emailAddress) | |
TextField("Your first name*", text: $firstName) | |
TextField("Your last name*", text: $lastName) |
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
struct Networking: View { | |
@ObservedObject var viewModel: NetworkingViewModel | |
// state to displau a sheet | |
@State private var isPresentingScanner = false | |
var body: some View { | |
let uiState = viewModel.uiState | |
NavigationView { | |
Group { |
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
// AppView.swift - Declare the tabs navigation. | |
TabView { | |
AgendaVM(agendaRepository: agendaRepository) | |
.tabItem { | |
Label("Agenda", systemImage: "calendar") | |
} | |
NetworkingVM(userRepository: userRepository) | |
.tabItem { | |
Label("Networking", systemImage: "person.2") |
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
@Composable | |
fun Chrono( | |
seconds: Int, | |
modifier: Modifier = Modifier | |
) { | |
val nbMarker = 60 | |
val progressAngle by animateFloatAsState( | |
targetValue = 360f / 30f * seconds, | |
animationSpec = tween(500) | |
) |
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
val progressAngle by animateFloatAsState( | |
targetValue = 360f / 30f * seconds, | |
animationSpec = tween(500) | |
) | |
val markerActives by animateFloatAsState( | |
targetValue = nbMarker / 30f * seconds, | |
animationSpec = tween(500) | |
) |
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
@Composable | |
fun animateFloatAsState( | |
targetValue: Float, | |
animationSpec: AnimationSpec<Float> = defaultAnimation, | |
visibilityThreshold: Float = 0.01f, | |
finishedListener: ((Float) -> Unit)? = null | |
) |
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
class TimerViewModel : ViewModel() { | |
private var job: Job? = null | |
private val _times = MutableStateFlow(0) | |
val times = _times.asStateFlow() | |
fun start(times: Int = 30) { | |
if (_times.value == 0) _times.value = times | |
job?.cancel() | |
job = viewModelScope.launch(Dispatchers.IO) { | |
while (isActive) { |
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
job = viewModelScope.launch(Dispatchers.IO) { | |
while (isActive) { | |
if (_times.value <= 0) { | |
job?.cancel() | |
return@launch | |
} | |
delay(timeMillis = 1000) | |
_times.value -= 1 | |
} | |
} |
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
@Composable | |
internal fun Marker( | |
angle: Int, | |
active: Boolean, | |
modifier: Modifier = Modifier | |
) { | |
Box( | |
modifier | |
.fillMaxSize() | |
.drawBehind { |
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
@Composable | |
internal fun CircleProgress( | |
angle: Float, | |
modifier: Modifier = Modifier | |
) { | |
Box( | |
modifier | |
.fillMaxSize() | |
.drawBehind { | |
drawArc( |
NewerOlder