Code Monkey home page Code Monkey logo

omentextfield's Introduction

OmenTextField

A better TextField for SwiftUI. A growing, multiline, auto-focusable TextField supporting bindable focus.

This has been pulled out of my flashcard app, Omen—in case you need some help memorizing SwiftUI overloads 😜

Example

A simple example app is included in the OmenTextFieldExample subproject.

Installation with Swift Package Manager

You can add OmenTextField to an Xcode project by adding it as a package dependency.

  1. From the File menu, select Swift Packages › Add Package Dependency…
  2. Paste "https://github.com/kitlangton/OmenTextField" into the package repository URL text field
  3. Hit Enter!

To-do List

  • iOS support (using UITextView)
  • macOS support (using NSTextView)
  • Add overrideable returnKey for iOS
  • Add onCommit callback

omentextfield's People

Contributors

kitlangton avatar williammo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

omentextfield's Issues

Automatic redraw when parent view is changed ?

import SwiftUI
import Introspect
import OmenTextField

extension Binding {
    func equalTo<A: Equatable>(_ value: A) -> Binding<Bool> where Value == A? {
        Binding<Bool> {
            wrappedValue == value
        } set: {
            if $0 {
                wrappedValue = value
            } else if wrappedValue == value {
                wrappedValue = nil
            }
        }
    }
}

struct ContentView: View {
    @State var content: String = ""
    @State var page2Active: Bool = true
    @State var focus: Focus?
    
    enum Focus {
        case first, second
    }
    
    var body: some View {
        if self.page2Active {
            HStack {
                OmenTextField(
                    "Input",
                    text: $content,
                    isFocused: $focus.equalTo(.first)
                )
            }
            .onAppear {
                DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
                    focus = .first
                }
            }
            .frame(width: .infinity, height: 30)
            .background(Color.gray)
            .cornerRadius(20)
            
            Button(action: {
                self.page2Active=false
                }) {
                    Text("switch to page1")
                }
        } else {
            Button(action: {
                self.page2Active=true
                }) {
                    Text("switch to page2")
                }
        }
       
            
    }
}

Above code wont display the text inside the OmenTextField after switching "pages", any clue how to resolve it ?

Thanks for great component

Edit : Display the text I mean whatever text we enter before switching pages

After setting the background color to white, the cursor disappears.

macos

When there is no content, after the focus is obtained, the cursor will not flash and is not displayed.

OmenTextField(
                        "Front",
                        text: $frontText,
                        isFocused: $focus.equalTo(.front),
                        returnKeyType: frontReturnKeyType,
                        onCommit: {
                            focus = .back
                        }
                    )
                    .border(Color(NSColor.gridColor))
                    .background(Color.white)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.