douglasjunior / react-native-keyboard-manager

⚛ Library to prevent issues of keyboard sliding up and cover inputs on React-Native iOS projects.
https://www.npmjs.com/package/react-native-keyboard-manager
MIT License
934 stars 60 forks source link

PrivacyInfo.xcprivacy build issue with Expo 51 #111

Closed lodev09 closed 2 months ago

lodev09 commented 2 months ago

Version 6.5.16-0 breaks IOS build due to invalid PrivacyInfo.xcprivacy with Expo 51.

❌  error: Multiple commands produce
'/Users/lodev09/Library/Developer/Xcode/DerivedData/XXXX.app/PrivacyInfo.xcprivacy'

I think we can safely ignore this since it will be up for the user to add the privacy file in their project. Expo does it via the app.json config.

Reverting to 6.5.11-2 works just fine.

douglasjunior commented 2 months ago

To use 6.5.16-0 you need to add this pod on your Podfile:

# Add temporary IQKeyboardManagerSwift fork to solve problems with PrivacyInfo.xcprivacy
pod 'IQKeyboardManagerSwift', :git => 'https://github.com/douglasjunior/IQKeyboardManager.git', :branch => 'react-native-keyboard-manager'

If you still in 6.5.11-2, you will have problems with Apple, because in this version the IQKeyboardManager have no PrivacyInfo.xcprivacy.

lodev09 commented 2 months ago

I just submitted a build to TestFlight using 6.5.11-2 just fine (didn't get that privacy email). As I mentioned, I'm using expo, which we don't normally modify the pod ourselves.

lodev09 commented 2 months ago

I guess you could put a note in the repo to use lower version when using expo?

douglasjunior commented 2 months ago

The right thing to do is to use the privacy manifest, IQKeyboardManager is listed on the Apple required third-party SDKs.

The proper version to this, right know, is the most recent that I published on NPM.

lodev09 commented 2 months ago

Have you tried building it using Expo? Maybe I missed something. All I can do is to downgrade to a lower version without the privacy manifest.

douglasjunior commented 2 months ago

Anyway, to use this library with expo you need to run the prebuild to get access to the native files.

https://docs.expo.dev/workflow/prebuild/

So just add this line o Podfile dependencies:

# Add temporary IQKeyboardManagerSwift fork to solve problems with PrivacyInfo.xcprivacy
pod 'IQKeyboardManagerSwift', :git => 'https://github.com/douglasjunior/IQKeyboardManager.git', :branch => 'react-native-keyboard-manager'
lodev09 commented 2 months ago

That defeats the purpose of expo CNG. I can however, create a custom config plugin for it but it's overkill and won't make sense.

What I'm trying to say is that there's NO issue with PrivacyInfo.xcprivacy if you're using Expo (and maybe in bare react-native as well) for as long as the user provides it in the app config. Here's the guide.

douglasjunior commented 2 months ago

I understand, but first of all, Expo is react-native, so if a package runs on React Native, this package should run with expo.

Furthermore, regardless of the framework, IQKeyboardManager must export its privacy manifest.

lodev09 commented 2 months ago

Okay.. if you must include the privacy manifest then it's all good. However, it needs to at least fix itself without needing to configure the pod. Building it with expo, without any modification of the Podfile, fails and that's bad dev experience. I'm just saying.

douglasjunior commented 2 months ago

The version 6 was outdated by IQKeyboardManager and version 7 is incompatible with React Native yet: https://github.com/douglasjunior/react-native-keyboard-manager/issues/109

So the only option was to fork the IQKeyboardManager version 6 and make the fix to work with the privacy manifest added only version 7.

Yes we MUST export privacy manifest for IQKeyboardManager: https://developer.apple.com/support/third-party-SDK-requirements/

Of course, it would be better to work without needing of a fork to be added to Podfile, that's obvious, and it's been like that for the last 7 years.

Unfortunately, this is how the open source world sometimes works, we need to play with the tools that we have in our hands.

samuelbeaulieu commented 1 month ago

I got it to work on Expo with the latest version with a plugin. Here's how:

  1. Create a new folder in the root of your project named plugins
  2. Create a file inside the newly created folder named withPodfile.js
const { withDangerousMod, withPlugins } = require('@expo/config-plugins');

const fs = require('fs');
const path = require('path');

async function readFile(path) {
  return fs.promises.readFile(path, 'utf8');
}

async function saveFile(path, content) {
  return fs.promises.writeFile(path, content, 'utf8');
}

module.exports = (config) =>
  withPlugins(config, [
    (config) => {
      return withDangerousMod(config, [
        'iOS',
        async (config) => {
          const file = path.join(config.modRequest.platformProjectRoot, 'Podfile');

          /*
           * You need to remove the line before adding it.
           * If you don't do this and you run `expo prebuild` in a dirt project
           * your file will have the same line added twice
           */
          const contents = (await readFile(file)).replace(
            /pod 'IQKeyboardManagerSwift', :git => 'https:\/\/github.com\/douglasjunior\/IQKeyboardManager.git', :branch => 'react-native-keyboard-manager'\n\n/g,
            '',
          );
          /*
           * Now re-adds the content
           */
          await saveFile(
            file,
            `pod 'IQKeyboardManagerSwift', :git => 'https://github.com/douglasjunior/IQKeyboardManager.git', :branch => 'react-native-keyboard-manager'\n\n${contents}`,
          );
          return config;
        },
      ]);
    },
  ]);
  1. Add your new plugin file to app.json
{
  "expo": {
    "name": "bidaction",
    ...
    "plugins": [
      ...
      "./plugins/withPodfile"
    ],
    ...
  }
}
  1. Rebuild the app with npx expo prebuild --clean
douglasjunior commented 1 month ago

Nice @samuelbeaulieu, I'm going to link your comment on README.

lodev09 commented 1 month ago

Apple just accepted my updates without the privacy file from this package FYI

douglasjunior commented 1 month ago

@lodev09 please man, don't be stubborn, take a look at the rules published by Apple:

image

Source: https://developer.apple.com/support/third-party-SDK-requirements/

And see that IQKeyboardManager is on the list:

image

You haven't had to use privacy yet because your app already existed before the rule was created.

Every new app now requires the PrivacyInfo for third-party SDKs.

lodev09 commented 1 month ago

Hey man, I'm just saying based on experience. Haven't submitted a new app yet so you might be right. It was just an FYI for those people using Expo and having build issues with this package.

Albert-Gao commented 1 month ago

I got it to work on Expo with the latest version with a plugin. Here's how:

  1. Create a new folder in the root of your project named plugins
  2. Create a file inside the newly created folder named withPodfile.js

Thanks so much for writing this plugin, however, I found it is only working after I updating the "iOS" to "ios", according to the latest of Expo doc (https://docs.expo.dev/config-plugins/plugins-and-mods/#experimental-functionality)

so this line:

 return withDangerousMod(config, [
        'iOS',

has to be

 return withDangerousMod(config, [
        'ios',