Skip to content

Commit

Permalink
[refactor] rename
Browse files Browse the repository at this point in the history
  • Loading branch information
zijievv committed Oct 4, 2023
1 parent e9c9985 commit ea2d605
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
13 changes: 12 additions & 1 deletion .swift-format
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@
"lineBreakBeforeEachGenericRequirement" : false,
"lineLength" : 120,
"maximumBlankLines" : 1,
"multiElementCollectionTrailingCommas" : true,
"noAssignmentInExpressions" : {
"allowedFunctions" : [
"XCTAssertNoThrow"
]
},
"prioritizeKeepingFunctionOutputTogether" : false,
"respectsExistingLineBreaks" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : false,
"AlwaysUseLowerCamelCase" : true,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
Expand All @@ -37,12 +44,16 @@
"NoLabelsInCasePatterns" : true,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoPlaygroundLiterals" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OneCasePerLine" : false,
"OmitExplicitReturns" : false,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : false,
"OrderedImports" : true,
"ReplaceForEachWithForLoop" : false,
"ReturnVoidInsteadOfEmptyTuple" : true,
"TypeNamesShouldBeCapitalized" : true,
"UseEarlyExits" : false,
"UseLetInEveryBoundCaseVariable" : true,
"UseShorthandTypeNames" : true,
Expand Down
2 changes: 1 addition & 1 deletion Example/Example/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct ContentView: View {
.font(.title3)
Text("Home")
.font(.system(.footnote, design: .rounded).weight(item == 0 ? .bold : .medium))
} actionWillSelect: {
} willSelect: {
if item == 0 {
text = ""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct ItemActionWillSelectPreferenceKey<Selection: Hashable>: PreferenceKey {
struct TabItemAction<Selection: Hashable>: Hashable, Equatable {
let selectedItemHashValue: Int?
let item: Selection
let action: ActionWillSelect?
let actionWillSelect: ActionWillSelect?

func hash(into hasher: inout Hasher) {
hasher.combine(selectedItemHashValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ struct TabItemViewModifier<Selection: Hashable, V: View>: ViewModifier {
@ViewBuilder private let itemBuilder: () -> V
private let actionWillSelect: ActionWillSelect?

init(item: Selection, @ViewBuilder itemBuilder: @escaping () -> V, actionWillSelect: ActionWillSelect?) {
init(item: Selection, @ViewBuilder itemBuilder: @escaping () -> V, willSelect action: ActionWillSelect?) {
self.item = item
self.itemBuilder = itemBuilder
self.actionWillSelect = actionWillSelect
self.actionWillSelect = action
}

func body(content: Content) -> some View {
Expand All @@ -40,7 +40,11 @@ struct TabItemViewModifier<Selection: Hashable, V: View>: ViewModifier {
.preference(
key: ItemActionWillSelectPreferenceKey.self,
value: [
item: TabItemAction(selectedItemHashValue: selectionHashValue, item: item, action: actionWillSelect)
item: TabItemAction(
selectedItemHashValue: selectionHashValue,
item: item,
actionWillSelect: actionWillSelect
)
]
)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/TabBarModule/Public/TabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public struct TabBar<Selection, Content>: View where Selection: Hashable, Conten
builder()
.contentShape(Rectangle())
.onTapGesture {
tabItemActions[item]?.action?()
tabItemActions[item]?.actionWillSelect?()
selection = item
}
.frame(width: width)
Expand Down
4 changes: 2 additions & 2 deletions Sources/TabBarModule/Public/View+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ extension View {
public func tabItem<Selection: Hashable, V: View>(
_ selection: Selection,
@ViewBuilder label: @escaping () -> V,
actionWillSelect: ActionWillSelect? = nil
willSelect action: ActionWillSelect? = nil
) -> some View {
modifier(TabItemViewModifier(item: selection, itemBuilder: label, actionWillSelect: actionWillSelect))
modifier(TabItemViewModifier(item: selection, itemBuilder: label, willSelect: action))
}

public func tabBarFill<S: ShapeStyle>(_ content: S, style: FillStyle = .init()) -> some View {
Expand Down

0 comments on commit ea2d605

Please sign in to comment.