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

iOS dictation is adding OBJ to string value #36521

Closed
gkasireddy202 opened this issue Mar 18, 2023 · 13 comments
Closed

iOS dictation is adding OBJ to string value #36521

gkasireddy202 opened this issue Mar 18, 2023 · 13 comments
Labels
Needs: Triage 🔍 Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@gkasireddy202
Copy link

Description

Hi,

When I use dictation adding text to TextInput in iOS.
OBJ is added to the text input value.
I am using iOS 16.
Please find the attached screenshot.

Thanks,
Screenshot 2023-03-15 at 6 43 07 PM

React Native Version

0.71.4

Output of npx react-native info

System:
OS: macOS 13.2.1
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Memory: 118.30 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 19.8.1 - /usr/local/bin/node
Yarn: Not Found
npm: 9.5.1 - /usr/local/bin/npm
Watchman: 2023.03.13.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.12.0 - /Users/gopi/.rvm/gems/ruby-2.7.6/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
Android SDK:
API Levels: 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33
Build Tools: 28.0.3, 29.0.2, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 32.1.0, 33.0.0
System Images: android-30 | Google APIs Intel x86 Atom, android-32 | Google APIs Intel x86 Atom_64, android-32 | Google Play Intel x86 Atom_64, android-33 | Google APIs Intel x86 Atom_64, android-33 | Google Play Intel x86 Atom_64
Android NDK: Not Found
IDEs:
Android Studio: 2021.2 AI-212.5712.43.2112.8609683
Xcode: 14.2/14C18 - /usr/bin/xcodebuild
Languages:
Java: 11.0.15 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.2.0 => 18.2.0
react-native: 0.71.4 => 0.71.4
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

  1. Click on dictation and start speaking.
  2. After the ending of the sentence.

Screenshot 2023-03-15 at 6 43 07 PM

A unique character OBJ is added to the text input value.

Snack, code example, screenshot, or link to a repository

import React, { Component } from 'react';
import { StyleSheet, View, Text, TouchableOpacity, TextInput } from 'react-native';
export default class App extends Component {

constructor(props) {
super(props);
this.state = {

  internalValue: ''


}

}

render() {
return (<View style={{ flex: 1 }}>

  <View style={{ flex: 1 }}>

  </View>

  <View style={{ flex: 2 }}>
    <View style={{ flex: 8 }}>
      <TextInput
        style={styles.textarea}
        onChangeText={(text) => this.setState({ internalValue: text })}
        value={this.state.internalValue}
        maxLength={120}
        multiline={true}
        placeholder={'Enter Text'}
        placeholderTextColor={'#c7c7c7'}
        underlineColorAndroid={'transparent'}
      />

    </View>
    <TouchableOpacity onPress={() => this.handleClickMe()} style={{ flex: 2, backgroundColor: 'green', margin: 20, alignItems: 'center', justifyContent: 'center' }}>

      <Text>Click me</Text>


    </TouchableOpacity>
  </View>
  <View style={{ flex: 3 }}>

  </View>




</View>)

}

}

const styles = StyleSheet.create({
container: {
flex: 1,
padding: 30,
justifyContent: 'center',
alignItems: 'center',
},
textareaContainer: {
height: 180,
padding: 5,
backgroundColor: '#F5FCFF',
},
textarea: {
textAlignVertical: 'top', // hack android
height: 170,
fontSize: 14,
color: '#333',
backgroundColor: 'white'
},
});

@chrisbobbe
Copy link

chrisbobbe commented Mar 20, 2023

#22139 may be related:

In iOS, when the text dictation ends, onKeyPress event is called for unknown reason.

  • The onKeyPress event return Backspace key which interfere with our text input logic.
  • The event with that key doesn't actually delete a letter.

Please consider removing it, thank you~!

Reading discussion at that issue, it looks like the React Native team confirmed it as a real issue in 2019 but decided to stop tracking it in the issue tracker.

I think a good first debugging step would be to check and see if onKeyPress is being called at the end of a dictation input. And if so, with what character.

@gkasireddy202
Copy link
Author

gkasireddy202 commented Mar 21, 2023 via email

@gkasireddy202
Copy link
Author

please provide a solution.
This is an odd issue faced by many users.

@zhurylo
Copy link

zhurylo commented May 20, 2023

onPress has nothing to do with this.

The "OBJ" character bug OR duplicate text bug only appears on iOS 16+ only and is due to "continuous dictation" introduced in iOS 16, - @Facebook/react-native/issues/36045

This issue has open peer review on React Native - @Facebook/react-native/pull/37188

Also, you can verify this by logging text.codePointAt(...) within the onChange method, which returns the value 65532, corresponding to the U+FFFC character.

The solution, for now, is to remove that char from the input:

handleOnChangeText = (text: string) => {
  const { onChangeText } = this.props;

  if (onChangeText) { 
     onChangeText(isIos ? text.replace(/\uFFFC/g, '') : text); 
  }
}

<TextInput>
   ...
   onChangeText={this.handleOnChangeText} 
   ...
</TextInput>

@hellohublot
Copy link
Contributor

Maybe it's because of the iOS saves \UFFFC to the back-end, so I assume the OBJ in your screenshot comes from other platforms such as Android platform, because on iOS platform this \UFFFC will actually be displayed as an dictation recognizing indicator

If you are using iOS native app, It will also have this \uFFFC, but when the dictation recognition ends, or you click other buttons, such as the send message button, the system will forcibly end the dictation, and this \UFFFC will also be removed by the system and will not be sent to the server

So I think #37188 may be able to solve your problem, because it can make the behavior consistent with iOS native

@gkasireddy202
Copy link
Author

@zhurylo - I replaced the OBJ value with an empty string using your example. Any other solution?

@SiobhyB
Copy link

SiobhyB commented May 30, 2023

Noting that this is also an issue in the WordPress mobile app, which we've worked around via the following code:

https://github.com/WordPress/gutenberg/blob/7cd7a0f53efc0af629ac211e10bd689fcc124e23/packages/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift#L768-L771

Following this issue so we can remove the hack when this is resolved.

@stharvey
Copy link

I'm encountering this exact same problem. My current workaround involves eliminating the problematic character when the data is received on the server side. I accomplish this using the PHP function below. The second replacement operation includes the "[OBJ]" character, which might not be visible if you're viewing this on an iOS/MacOS device.

function removeUfffc($text) {
  $text = str_replace("\ufffc", "", $text);
  $text = str_replace("", "", $text);

  return $text;
}

@gkasireddy202
Copy link
Author

@stharvey - Thanks for the reply. I worked on this example. The below one is working fine.
@zhurylo - suggested the below example.

handleOnChangeText = (text: string) => {
const { onChangeText } = this.props;

if (onChangeText) {
onChangeText(isIos ? text.replace(/\uFFFC/g, '') : text);
}
}

... onChangeText={this.handleOnChangeText} ...

Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 24, 2023
Copy link

This issue was closed because it has been stalled for 7 days with no activity.

@fabOnReact
Copy link
Contributor

Do you still experience this issue?

I have four years of experience maintaining facebook/react-native and I specialize in the Text and TextInput components. I currently have 58 facebook/react-native PRs.

If you still experience this issue, I will prepare a patched release with the fix.

Thanks a lot

@gkasireddy202
Copy link
Author

gkasireddy202 commented Jan 18, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Triage 🔍 Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

8 participants