Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALTAPPS-1340: Shared, iOS code blanks if statement #1175

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<ID>ImplicitDefaultLocale:TimeIntervalUtil.kt$TimeIntervalUtil$String.format("%02d:00 \u2014 %02d:00", i, i + 1)</ID>
<ID>InvalidPackageDeclaration:HandleActions.kt$package org.hyperskill.app.core.view</ID>
<ID>LambdaParameterInRestartableEffect:OnComposableShownFirstTime.kt$block</ID>
<ID>LargeClass:StepQuizCodeBlanksReducer.kt$StepQuizCodeBlanksReducer : StateReducer</ID>
<ID>LargeClass:StepQuizReducer.kt$StepQuizReducer : StateReducer</ID>
<ID>LongMethod:AppReducer.kt$AppReducer$private fun handleFetchAppStartupConfigSuccess( state: State, message: Message.FetchAppStartupConfigSuccess ): ReducerResult</ID>
<ID>LongMethod:ChallengeCard.kt$@Composable fun ChallengeCard( viewState: ChallengeWidgetViewState, onNewMessage: (Message) -&gt; Unit )</ID>
Expand All @@ -67,6 +68,7 @@
<ID>LongMethod:ProblemOfDayCardFormDelegate.kt$ProblemOfDayCardFormDelegate$fun render( dateFormatter: SharedDateFormatter, binding: LayoutProblemOfTheDayCardBinding, state: HomeFeature.ProblemOfDayState, areProblemsLimited: Boolean )</ID>
<ID>LongMethod:ProfileBadges.kt$@Composable fun ProfileBadges( viewState: BadgesViewState, windowWidthSizeClass: WindowWidthSizeClass, onBadgeClick: (BadgeKind) -&gt; Unit, onExpandButtonClick: (ProfileFeature.Message.BadgesVisibilityButton) -&gt; Unit, modifier: Modifier = Modifier )</ID>
<ID>LongMethod:ProfileSettingsDialogFragment.kt$ProfileSettingsDialogFragment$override fun onViewCreated(view: View, savedInstanceState: Bundle?)</ID>
<ID>LongMethod:StepQuizCodeBlanksReducer.kt$StepQuizCodeBlanksReducer$private fun createInitialCodeBlocks(step: Step): List&lt;CodeBlock&gt;</ID>
<ID>LongMethod:StepQuizCodeBlanksReducer.kt$StepQuizCodeBlanksReducer$private fun handleDeleteButtonClicked( state: State ): StepQuizCodeBlanksReducerResult?</ID>
<ID>LongMethod:StepQuizCodeBlanksReducer.kt$StepQuizCodeBlanksReducer$private fun handleSpaceButtonClicked( state: State ): StepQuizCodeBlanksReducerResult?</ID>
<ID>LongMethod:StepQuizCodeBlanksReducer.kt$StepQuizCodeBlanksReducer$private fun handleSuggestionClicked( state: State, message: Message.SuggestionClicked ): StepQuizCodeBlanksReducerResult?</ID>
Expand Down Expand Up @@ -204,6 +206,7 @@
<ID>ModifierWithoutDefault:BadgeImage.kt$modifier</ID>
<ID>NestedBlockDepth:AuthSocialWebViewClient.kt$AuthSocialWebViewClient$override fun shouldOverrideUrlLoading( view: WebView?, request: WebResourceRequest? ): Boolean</ID>
<ID>NestedBlockDepth:StepQuizCodeBlanksReducer.kt$StepQuizCodeBlanksReducer$private fun setCodeBlockIsActive(codeBlock: CodeBlock, isActive: Boolean): CodeBlock</ID>
<ID>NestedBlockDepth:StepQuizCodeBlanksViewStateMapper.kt$StepQuizCodeBlanksViewStateMapper$private fun mapContentState( state: StepQuizCodeBlanksFeature.State.Content ): StepQuizCodeBlanksViewState.Content</ID>
<ID>PreviewPublic:BadgeCard.kt$BadgeCardPreview</ID>
<ID>PreviewPublic:BadgeCard.kt$LastLevelBadgeCardPreview</ID>
<ID>PreviewPublic:BadgeGrid.kt$PhoneBadgeGridPreview</ID>
Expand Down Expand Up @@ -248,6 +251,7 @@
<ID>ReturnCount:SearchReducer.kt$SearchReducer$private fun handleSearchResultsItemClickedMessage( state: State, message: Message.SearchResultsItemClicked ): SearchReducerResult?</ID>
<ID>ReturnCount:SharedDateFormatter.kt$SharedDateFormatter$fun formatTimeDistance(millis: Long): String</ID>
<ID>ReturnCount:StateExtentions.kt$internal fun ChallengeWidgetFeature.State.Content.setCurrentChallengeIntervalProgressAsCompleted(): Challenge?</ID>
<ID>ReturnCount:StepQuizCodeBlanksReducer.kt$StepQuizCodeBlanksReducer$private fun handleDecreaseIndentLevelButtonClicked( state: State ): StepQuizCodeBlanksReducerResult?</ID>
<ID>ReturnCount:StepQuizCodeBlanksReducer.kt$StepQuizCodeBlanksReducer$private fun handleDeleteButtonClicked( state: State ): StepQuizCodeBlanksReducerResult?</ID>
<ID>ReturnCount:StepQuizCodeBlanksReducer.kt$StepQuizCodeBlanksReducer$private fun handleSpaceButtonClicked( state: State ): StepQuizCodeBlanksReducerResult?</ID>
<ID>ReturnCount:StepQuizCodeBlanksReducer.kt$StepQuizCodeBlanksReducer$private fun handleSuggestionClicked( state: State, message: Message.SuggestionClicked ): StepQuizCodeBlanksReducerResult?</ID>
Expand Down
94 changes: 81 additions & 13 deletions iosHyperskillApp/iosHyperskillApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,14 @@ extension StepQuizViewModel: StepQuizCodeBlanksOutputProtocol {
)
)
}

func handleStepQuizCodeBlanksDidTapDecreaseIndentLevel() {
onNewMessage(
StepQuizFeatureMessageStepQuizCodeBlanksMessage(
message: StepQuizCodeBlanksFeatureMessageDecreaseIndentLevelButtonClicked()
)
)
}
}

// MARK: - StepQuizViewModel: StepQuizProblemOnboardingModalViewControllerDelegate -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ protocol StepQuizCodeBlanksOutputProtocol: AnyObject {
func handleStepQuizCodeBlanksDidTapDelete()
func handleStepQuizCodeBlanksDidTapEnter()
func handleStepQuizCodeBlanksDidTapSpace()
func handleStepQuizCodeBlanksDidTapDecreaseIndentLevel()
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ final class StepQuizCodeBlanksViewModel {
impactFeedbackGenerator.triggerFeedback()
moduleOutput?.handleStepQuizCodeBlanksDidTapSpace()
}

@MainActor
func doDecreaseIndentLevelAction() {
impactFeedbackGenerator.triggerFeedback()
moduleOutput?.handleStepQuizCodeBlanksDidTapDecreaseIndentLevel()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ extension StepQuizCodeBlanksActionButton {
action: action
)
}

static func decreaseIndentLevel(action: @escaping () -> Void) -> StepQuizCodeBlanksActionButton {
StepQuizCodeBlanksActionButton(
appearance: .init(
padding: LayoutInsets(
horizontal: LayoutInsets.smallInset,
vertical: 5.5
)
),
imageSystemName: "arrow.left.to.line",
action: action
)
}
}

#if DEBUG
Expand All @@ -71,12 +84,14 @@ extension StepQuizCodeBlanksActionButton {
StepQuizCodeBlanksActionButton.delete(action: {})
StepQuizCodeBlanksActionButton.enter(action: {})
StepQuizCodeBlanksActionButton.space(action: {})
StepQuizCodeBlanksActionButton.decreaseIndentLevel(action: {})
}

HStack {
StepQuizCodeBlanksActionButton.delete(action: {})
StepQuizCodeBlanksActionButton.enter(action: {})
StepQuizCodeBlanksActionButton.space(action: {})
StepQuizCodeBlanksActionButton.decreaseIndentLevel(action: {})
}
.disabled(true)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import SwiftUI

struct StepQuizCodeBlanksActionButtonsView: View {
let isDeleteButtonEnabled: Bool
let isSpaceButtonHidden: Bool
let isDecreaseIndentLevelButtonHidden: Bool

let onSpaceTap: () -> Void
let onDeleteTap: () -> Void
let onEnterTap: () -> Void
let onDecreaseIndentLevelTap: () -> Void

var body: some View {
HStack(spacing: LayoutInsets.defaultInset) {
Spacer()

if !isDecreaseIndentLevelButtonHidden {
StepQuizCodeBlanksActionButton
.decreaseIndentLevel(action: onDecreaseIndentLevelTap)
}

if !isSpaceButtonHidden {
StepQuizCodeBlanksActionButton
.space(action: onSpaceTap)
}

StepQuizCodeBlanksActionButton
.delete(action: onDeleteTap)
.disabled(!isDeleteButtonEnabled)

StepQuizCodeBlanksActionButton
.enter(action: onEnterTap)
}
.padding(.horizontal)
}
}

#if DEBUG
#Preview {
VStack {
StepQuizCodeBlanksActionButtonsView(
isDeleteButtonEnabled: false,
isSpaceButtonHidden: false,
isDecreaseIndentLevelButtonHidden: false,
onSpaceTap: {},
onDeleteTap: {},
onEnterTap: {},
onDecreaseIndentLevelTap: {}
)

StepQuizCodeBlanksActionButtonsView(
isDeleteButtonEnabled: true,
isSpaceButtonHidden: true,
isDecreaseIndentLevelButtonHidden: true,
onSpaceTap: {},
onDeleteTap: {},
onEnterTap: {},
onDecreaseIndentLevelTap: {}
)
}
.padding()
}
#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SwiftUI

struct StepQuizCodeBlanksBlankView: View {
struct StepQuizCodeBlanksCodeBlockChildBlankView: View {
var width: CGFloat = 208
var height: CGFloat = 48

Expand All @@ -17,7 +17,7 @@ struct StepQuizCodeBlanksBlankView: View {
}
}

extension StepQuizCodeBlanksBlankView {
extension StepQuizCodeBlanksCodeBlockChildBlankView {
init(style: Style, isActive: Bool) {
let size = style.size
self.init(width: size.width, height: size.height, isActive: isActive)
Expand All @@ -41,8 +41,8 @@ extension StepQuizCodeBlanksBlankView {
#if DEBUG
#Preview {
VStack {
StepQuizCodeBlanksBlankView(style: .small, isActive: true)
StepQuizCodeBlanksBlankView(style: .large, isActive: false)
StepQuizCodeBlanksCodeBlockChildBlankView(style: .small, isActive: true)
StepQuizCodeBlanksCodeBlockChildBlankView(style: .large, isActive: false)
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SwiftUI

extension StepQuizCodeBlanksOptionView {
extension StepQuizCodeBlanksCodeBlockChildTextView {
enum Appearance {
static let insets = LayoutInsets(horizontal: 12, vertical: LayoutInsets.smallInset)
static let minWidth: CGFloat = 48
Expand All @@ -9,7 +9,7 @@ extension StepQuizCodeBlanksOptionView {
}
}

struct StepQuizCodeBlanksOptionView: View {
struct StepQuizCodeBlanksCodeBlockChildTextView: View {
let text: String

let isActive: Bool
Expand All @@ -31,9 +31,9 @@ struct StepQuizCodeBlanksOptionView: View {
#if DEBUG
#Preview {
VStack {
StepQuizCodeBlanksOptionView(text: "print", isActive: false)
StepQuizCodeBlanksOptionView(text: "There is a cat on the keyboard, it is true", isActive: true)
StepQuizCodeBlanksOptionView(text: "Typing messages out of the blue", isActive: true)
StepQuizCodeBlanksCodeBlockChildTextView(text: "print", isActive: false)
StepQuizCodeBlanksCodeBlockChildTextView(text: "There is a cat on the keyboard, it is true", isActive: true)
StepQuizCodeBlanksCodeBlockChildTextView(text: "Typing messages out of the blue", isActive: true)
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ struct StepQuizCodeBlanksCodeBlockChildView: View {
child: StepQuizCodeBlanksViewStateCodeBlockChildItem
) -> some View {
if let value = child.value {
StepQuizCodeBlanksOptionView(text: value, isActive: child.isActive)
StepQuizCodeBlanksCodeBlockChildTextView(text: value, isActive: child.isActive)
} else {
StepQuizCodeBlanksBlankView(style: .small, isActive: child.isActive)
StepQuizCodeBlanksCodeBlockChildBlankView(style: .small, isActive: child.isActive)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import shared
import SwiftUI

struct StepQuizCodeBlanksIfStatementView: View {
let ifStatementItem: StepQuizCodeBlanksViewStateCodeBlockItemIfStatement

let onChildTap: (StepQuizCodeBlanksViewStateCodeBlockChildItem) -> Void

var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack(alignment: .center, spacing: LayoutInsets.smallInset) {
Text("if")
.font(StepQuizCodeBlanksAppearance.blankFont)
.foregroundColor(StepQuizCodeBlanksAppearance.blankTextColor)

ForEach(ifStatementItem.children, id: \.id) { child in
StepQuizCodeBlanksCodeBlockChildView(child: child, action: onChildTap)
}

Text(":")
.font(StepQuizCodeBlanksAppearance.blankFont)
.foregroundColor(StepQuizCodeBlanksAppearance.blankTextColor)
}
.padding(.horizontal, LayoutInsets.defaultInset)
.padding(.vertical, LayoutInsets.smallInset)
.background(Color(ColorPalette.violet400Alpha7))
.cornerRadius(StepQuizCodeBlanksAppearance.cornerRadius)
.padding(.horizontal)
}
.scrollBounceBehaviorBasedOnSize(axes: .horizontal)
}
}

#if DEBUG
#Preview {
VStack {
StepQuizCodeBlanksIfStatementView(
ifStatementItem: StepQuizCodeBlanksViewStateCodeBlockItemIfStatement(
id: 0,
indentLevel: 0,
children: [
StepQuizCodeBlanksViewStateCodeBlockChildItem(id: 0, isActive: true, value: nil)
]
),
onChildTap: { _ in }
)

StepQuizCodeBlanksIfStatementView(
ifStatementItem: StepQuizCodeBlanksViewStateCodeBlockItemIfStatement(
id: 0,
indentLevel: 0,
children: [
StepQuizCodeBlanksViewStateCodeBlockChildItem(id: 0, isActive: true, value: "x")
]
),
onChildTap: { _ in }
)

StepQuizCodeBlanksIfStatementView(
ifStatementItem: StepQuizCodeBlanksViewStateCodeBlockItemIfStatement(
id: 0,
indentLevel: 0,
children: [
StepQuizCodeBlanksViewStateCodeBlockChildItem(id: 0, isActive: false, value: "x"),
StepQuizCodeBlanksViewStateCodeBlockChildItem(id: 1, isActive: true, value: nil)
]
),
onChildTap: { _ in }
)
}
.padding()
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,31 @@ struct StepQuizCodeBlanksPrintInstructionView: View {
StepQuizCodeBlanksPrintInstructionView(
printItem: StepQuizCodeBlanksViewStateCodeBlockItemPrint(
id: 0,
indentLevel: 0,
children: [.init(id: 0, isActive: false, value: "")]
),
onChildTap: { _ in }
)
StepQuizCodeBlanksPrintInstructionView(
printItem: StepQuizCodeBlanksViewStateCodeBlockItemPrint(
id: 0,
indentLevel: 0,
children: [.init(id: 0, isActive: true, value: "")]
),
onChildTap: { _ in }
)
StepQuizCodeBlanksPrintInstructionView(
printItem: StepQuizCodeBlanksViewStateCodeBlockItemPrint(
id: 0,
indentLevel: 0,
children: [.init(id: 0, isActive: true, value: "There is a cat on the keyboard, it is true")]
),
onChildTap: { _ in }
)
StepQuizCodeBlanksPrintInstructionView(
printItem: StepQuizCodeBlanksViewStateCodeBlockItemPrint(
id: 0,
indentLevel: 0,
children: [.init(id: 0, isActive: false, value: "There is a cat on the keyboard, it is true")]
),
onChildTap: { _ in }
Expand All @@ -66,6 +70,7 @@ struct StepQuizCodeBlanksPrintInstructionView: View {
StepQuizCodeBlanksPrintInstructionView(
printItem: StepQuizCodeBlanksViewStateCodeBlockItemPrint(
id: 0,
indentLevel: 0,
children: [
.init(id: 0, isActive: false, value: "x"),
.init(id: 1, isActive: true, value: "")
Expand Down
Loading
Loading