Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Block editor: change block type #1047

Draft
wants to merge 47 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
3d63d04
Begin stubbing out block select menu view
gordonbrander Dec 21, 2023
bbc1577
Set height as multiple of AppTheme.unit
gordonbrander Dec 21, 2023
b893001
Stub in drag gesture (unfinished)
gordonbrander Dec 21, 2023
1f8fda1
Wrap select menu in frame view
gordonbrander Dec 21, 2023
c422288
Horizontally scroll items
gordonbrander Dec 21, 2023
1104451
Stub in delete action
gordonbrander Dec 21, 2023
804d87a
Update delete action
gordonbrander Dec 21, 2023
ea01d26
Introduce Theme, ButtonTheme, and ButtonRoleTheme
gordonbrander Dec 22, 2023
3480909
Rename view
gordonbrander Dec 22, 2023
65af9fd
Make top level block editor a SwiftUI View
gordonbrander Dec 22, 2023
eac5495
Factor out ControllerModelProtocol
gordonbrander Dec 22, 2023
90c37e7
Share store with select menu
gordonbrander Dec 22, 2023
ec4740e
Remove ControllerModelProtocol
gordonbrander Dec 22, 2023
c4fff47
Wire drag/dismiss gesture into store
gordonbrander Dec 26, 2023
b1960fb
Introduce selected stroke to buttons
gordonbrander Dec 26, 2023
f57504e
Allow including a border color with Theme
gordonbrander Dec 26, 2023
4b4e93e
Stub in select mode menu item
gordonbrander Dec 28, 2023
2a1dae3
Iron out some of the select/select menu transition
gordonbrander Jan 3, 2024
82f6c6e
Allow exit select mode by dragging block menu
gordonbrander Jan 3, 2024
dd0a24f
Fix tests
gordonbrander Jan 8, 2024
c90a782
Toggle cell selection on tap
gordonbrander Jan 8, 2024
d1c0676
Animate selection
gordonbrander Jan 8, 2024
9d42106
Update block views using fluent helpers
gordonbrander Jan 29, 2024
2890c32
Set background on all cells
gordonbrander Jan 30, 2024
6e3ea03
Add Color extension to define dynamic light/dark
gordonbrander Jan 30, 2024
6ff6d30
Fix tertiary label
gordonbrander Jan 30, 2024
f5bec4f
Tighten up padding on blocks
gordonbrander Jan 30, 2024
5500a25
Add hStack helper
gordonbrander Jan 30, 2024
a2825b7
Add radio button view for block selection
gordonbrander Jan 30, 2024
557e436
Refactor blocks to share more model
gordonbrander Jan 31, 2024
689fe2f
Layer select view under block
gordonbrander Jan 31, 2024
9852410
Set background of hosting view clear
gordonbrander Jan 31, 2024
f35fa55
Begin theming editor
gordonbrander Jan 31, 2024
ab823fa
Fix bullet alignment
gordonbrander Feb 1, 2024
bcb13d0
Set opacity on select view as well as background
gordonbrander Feb 1, 2024
d8d6ad8
Exit block select mode when deselecting last block
gordonbrander Feb 1, 2024
f2cfe98
Resolve some block editor menu state issues
gordonbrander Feb 1, 2024
d077ee7
Fix some missing animations in state transition
gordonbrander Feb 1, 2024
1cfc533
Stub in text block conversion
gordonbrander Feb 2, 2024
6c1f868
Stub in block conversion code
gordonbrander Feb 2, 2024
20e38c0
Set alpha, not opacity
gordonbrander Feb 2, 2024
ac4c58e
Fix loading bug for new drafts
gordonbrander Feb 2, 2024
7225721
Stub in audience
gordonbrander Feb 5, 2024
6defb25
Merge remote-tracking branch 'origin/main' into 2023-12-21-block-edit…
gordonbrander Feb 7, 2024
3c64c46
Fix test
gordonbrander Feb 7, 2024
2d25137
Set theme color on outer block editor element
gordonbrander Feb 7, 2024
27e22ab
Make background clear
gordonbrander Feb 9, 2024
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
15 changes: 14 additions & 1 deletion xcode/Subconscious/Shared/AppTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extension Color {
static let icon = SwiftUI.Color.accentColor
static let secondaryIcon = SwiftUI.Color.secondary
static let tertiaryIcon = SwiftUI.Color(
uiColor: UIColor.tertiarySystemFill
uiColor: UIColor.tertiaryLabel
)
static let buttonText = SwiftUI.Color.accentColor
/// Fill for pressed-state overlays
Expand Down Expand Up @@ -188,3 +188,16 @@ extension UIColor {
UIColor(Color.accentColor)
}
}

extension ShadowStyle {
static func brandShadowLg(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduce the concept of shadow presets. In future we will want to systematize our shadows so as to have a coherent sense of distance and lighting.

_ colorScheme: ColorScheme
) -> ShadowStyle {
ShadowStyle(
color: Color.brandDropShadow(colorScheme).opacity(0.5),
radius: 8,
x: 0,
y: 4
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ struct MemoEditorDetailView: View {
}

private func blockEditor() -> some View {
BlockEditor.Representable(
BlockEditor.BlockEditorView(
store: blockEditorStore
)
.frame(
Expand Down
161 changes: 161 additions & 0 deletions xcode/Subconscious/Shared/Library/ColorUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,144 @@

import SwiftUI

extension UIColor {
convenience init(
light lightModeColor: UIColor,
dark darkModeColor: UIColor
) {
self.init { traitCollection in
switch traitCollection.userInterfaceStyle {
case .light:
return lightModeColor
case .dark:
return darkModeColor
default:
return lightModeColor
}
}
}
}

extension Color {
init(
light lightModeColor: Color,
dark darkModeColor: Color
) {
self.init(
UIColor(
light: UIColor(lightModeColor),
dark: UIColor(darkModeColor)
)
)
}
}

extension Color {
/// A color theme describes a foreground, background, and border
struct Theme: Hashable {
var foreground: Color
var background: Color
var border: Color = .clear
}
}

extension View {
/// Apply a theme to this view
func theme(_ theme: Color.Theme) -> some View {
self
.foregroundStyle(theme.foreground)
.background(theme.background)
}
}



extension Color {
/// Describe themes for all states of a button
struct ButtonTheme: Hashable {
var normal: Theme
var pressed: Theme
var disabled: Theme

/// Describes a button state
enum State: Hashable {
case normal
case pressed
case disabled

init(
isPressed: Bool,
isEnabled: Bool = true
) {
guard isEnabled else {
self = .disabled
return
}
guard !isPressed else {
self = .pressed
return
}
self = .normal
}
}

/// Choose a theme given a button state
func choose(_ state: ButtonTheme.State) -> Theme {
switch state {
case .normal:
return normal
case .pressed:
return pressed
case .disabled:
return disabled
}
}
}
}

extension View {
/// Apply a button theme to this view for a given state
func theme(
_ buttonTheme: Color.ButtonTheme,
state: Color.ButtonTheme.State
) -> some View {
let theme = buttonTheme.choose(state)
return self
.animation(.default, value: state)
.theme(theme)
}

/// Apply a button theme to this view depending on whether it is
/// enabled, pressed, etc.
func theme(
_ buttonTheme: Color.ButtonTheme,
isPressed: Bool,
isEnabled: Bool = true
) -> some View {
theme(
buttonTheme,
state: .init(isPressed: isPressed, isEnabled: isEnabled)
)
}
}

extension Color {
/// Describe button themes for multiple roles
struct ButtonRoleTheme: Hashable {
var normal: ButtonTheme
var destructive: ButtonTheme

func forRole(_ buttonRole: ButtonRole? = nil) -> ButtonTheme {
switch buttonRole {
case let .some(role) where role == .destructive:
return destructive
default:
return normal
}
}
}
}

extension Color {
static func chooseForState(
isPressed: Bool,
Expand All @@ -26,3 +164,26 @@ extension Color {
}
}
}

struct ColorUtilities_Previews: PreviewProvider {
static var previews: some View {
VStack {
Text("Hello world")
.padding()
.theme(
.init(
foreground: .blue,
background: .secondaryBackground
)
)
Text("Hello world")
.padding()
.theme(
.init(
foreground: .red,
background: .secondaryBackground
)
)
}
}
}
Loading