iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🍄

SwiftUI TextEditor Only Allows 30 Characters? It Was the Simeji Keyboard

に公開

🧐 What Happened?

While running the review evaluation screen I created last time on a real device, I noticed something.

↓ Here is the previous article:
https://zenn.dev/funya3/articles/e402b65ab27c9b

😥 Can I Only Enter 30 Characters for Hiragana and Alphabet?

It seems that only 30 characters can be entered.
Here is a GIF of actually entering characters.

When Entering Hiragana When Entering Alphabet
Hiragana Alphabet

🧑‍💻 Rechecking the Code I Used

Below is the code for the review evaluation screen I actually used.
I'm using TextEditor, but there is no code that limits the number of characters.

Full Code
import SwiftUI

struct RatingDialogView: View {
    @Binding var isPresented: Bool
    @State private var rating: Int = 0
    @State private var inputText = ""

    var body: some View {
        VStack(spacing: 16) {
            Text("ドライバーの評価をお願いします")
                .font(.headline)

            Image(systemName: "person.crop.circle.fill")
                .resizable()
                .frame(width: 80, height: 80)
                .clipShape(Circle())
                .foregroundColor(.gray)

            Text("ダミー会社名株式会社")
                .font(.body)
                .foregroundColor(.secondary)

            Divider()

            Text("今回の満足度と評価をご入力ください。")
                .font(.callout)

            HStack(spacing: 8) {
                ForEach(1...5, id: \.self) { index in
                    Image(systemName: rating >= index ? "star.fill" : "star")
                        .resizable()
                        .frame(width: 28, height: 28)
                        .foregroundColor(rating >= index ? .yellow : .gray)
                        .onTapGesture {
                            rating = index
                        }
                }
            }

            TextEditor(text: $inputText)
                .frame(height: 100)
                .padding(4)
                .overlay(
                    RoundedRectangle(cornerRadius: 8)
                        .stroke(Color.gray, lineWidth: 1)
                )
                .overlay(alignment: .topLeading) {
                    if inputText.isEmpty {
                        Text("運転が丁寧で親切なドライバーさんでした")
                            .foregroundColor(Color(uiColor: .placeholderText))
                            .padding(8)
                    }
                }

            Button(action: {
                print("評価送信: \(rating) ★, コメント: \(inputText)")
                isPresented = false // close
            }) {
                Text("評価する")
                    .frame(maxWidth: .infinity)
                    .padding()
                    .background(rating > 0 ? Color.blue : Color.gray)
                    .foregroundColor(.white)
                    .cornerRadius(8)
            }
            .disabled(rating == 0)
        }
        .padding()
        .background(Color.white)
        .cornerRadius(16)
        .shadow(radius: 10)
        .padding()
    }
}

#Preview {
    RatingDialogView(isPresented: .constant(true))
}

If only 30 characters could be entered, I would have expected code like the following:
But looking at the code above, there is no count > 30 anywhere.
So why could I only enter 30 characters?

var other: String {
    didSet {
        if other.count > 30 {
            other = String(other.prefix(30))
        }
    }
}

🍄 The Cause Was the 'Simeji' Keyboard!

Actually, I usually use a third-party Japanese input keyboard called Simeji.
↓ This was the cause.
https://apps.apple.com/jp/app/simeji-フォントから顔文字-絵文字までaiキーボード/id899997582

Results of Trying Other Keyboards

When I tried the iPhone standard keyboard and a keyboard called grammaly, I confirmed that I could enter more than 30 characters.

iPhone Standard Keyboard grammaly Keyboard

Further Investigation: Verification with Standard Notes

Here are the results of entering characters into the iPhone Notes app with Simeji.
Pressing the Confirm button allowed input of more than 30 characters.
In other words, it seems that an input limit was imposed while the text was unconfirmed.

Notes + Simeji (Unconfirmed) 'Confirm' After 30 Characters

Conclusion Summary

  • There is no character limit code written for SwiftUI's TextEditor
  • The fact that only 30 characters could be entered was due to the behavior of the Simeji keyboard
  • Character input can stop midway while the text remains unconfirmed
  • Pressing the 'Confirm' button allows input without issues

Lastly: For Those With the Same Problem

If TextEditor or TextField seems to have a limit,
it might be worth suspecting the influence of a third-party keyboard.


Thank you for reading this far!
I hope this helps someone with the same problem 🙇‍♀️

Discussion