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

feat: install share app extension on Android #893

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 1 addition & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ android {

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
compile project(':react-native-share-extension')
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules

Expand Down
15 changes: 15 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@
android:screenOrientation="portrait"
></activity>

<activity
android:noHistory="true"
android:name=".share.ShareActivity"
android:configChanges="orientation"
android:label="@string/title_activity_share"
android:screenOrientation="portrait"
android:theme="@style/Theme.Share.Transparent"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>

<activity-alias
android:name="io.cozy.flagship.mobile.MainActivitycozy"
android:enabled="true"
Expand Down
13 changes: 13 additions & 0 deletions android/app/src/main/java/share/ShareActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.cozy.flagship.mobile.share;

import com.facebook.react.ReactActivity;


public class ShareActivity extends ReactActivity {
acezard marked this conversation as resolved.
Show resolved Hide resolved
@Override
protected String getMainComponentName() {
// this is the name AppRegistry will use to launch the Share View
return "MyShareEx";
Copy link
Member

Choose a reason for hiding this comment

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

Should we customize this name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Ldoppea yeah, I kept the same because it was simpler to follow documentation, but not sure what name we should use. Do you have any suggestion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • Updated

}

}
38 changes: 38 additions & 0 deletions android/app/src/main/java/share/ShareApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.cozy.flagship.mobile.share;
import io.cozy.flagship.mobile.BuildConfig;

import com.alinz.parkerdan.shareextension.SharePackage;

import android.app.Application;

import com.facebook.react.shell.MainReactPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactPackage;

import java.util.Arrays;
import java.util.List;


public class ShareApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;

}

@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new SharePackage()
);
}
};

@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
1 change: 1 addition & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">Cozy</string>
<string name="title_activity_share">MyShareEx</string>
</resources>
14 changes: 14 additions & 0 deletions android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,18 @@
<item name="android:windowTranslucentNavigation">true</item>
</style>

<style name="Share.Window" parent="android:Theme">
<item name="android:windowEnterAnimation">@null</item>
<item name="android:windowExitAnimation">@null</item>
</style>

<style name="Theme.Share.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowAnimationStyle">@style/Share.Window</item>
</style>
</resources>
2 changes: 2 additions & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ include ':react-native-fs'
project(':react-native-fs').projectDir = new File(settingsDir, '../node_modules/react-native-fs/android')
include ':react-native-google-safetynet'
project(':react-native-google-safetynet').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-safetynet/android')
include ':app', ':react-native-share-extension'
project(':react-native-share-extension').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-share-extension/android')
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"react-native-play-install-referrer": "^1.1.8",
"react-native-safe-area-context": "^4.5.0",
"react-native-screens": "3.18.2",
"react-native-share-extension": "2.0.0",
"react-native-svg": "12.3.0",
"react-native-url-polyfill": "^1.3.0",
"react-native-web": "0.17.7",
Expand Down
45,350 changes: 45,350 additions & 0 deletions patches/react-native-share-extension+2.0.0.patch

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/app/view/Share/ShareComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import { View, Text } from 'react-native'

export const Share = (): JSX.Element => {
return (
<View>
<Text>Share Extension Placeholder</Text>
</View>
)
}
1 change: 1 addition & 0 deletions src/constants/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"maps:*",
"geo:*"
],
"SHARE_APP_NAME": "MyShareEx",
"appTouched": "appTouched",
"authLogin": "/auth/login?redirect=",
"konnectors": {
Expand Down
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { AppRegistry } from 'react-native'

import App from './App'
import { name as appName } from './app.json'
import App from '/App'
import { name as appName } from '/app.json'
import { ShareComponent } from '/app/view/Share/ShareComponent'
import { SHARE_APP_NAME as shareAppName } from '/constants/strings.json'

AppRegistry.registerComponent(appName, () => App)
AppRegistry.registerComponent(shareAppName, () => ShareComponent)
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14450,6 +14450,11 @@ react-native-securerandom@^0.1.1:
dependencies:
base64-js "*"

[email protected]:
version "2.0.0"
resolved "https://registry.yarnpkg.com/react-native-share-extension/-/react-native-share-extension-2.0.0.tgz#c645715ce6c937e1dd527c4df5635df89ca88a44"
integrity sha512-LWbyGd3Vu5m0TBvSado2NE4MJ5R3iRw4WpoT+6ptHNir19pM/inNQaFh+OiySLNNy5N058pFmWq3LFNA4DPZkg==

[email protected]:
version "1.0.0"
resolved "https://registry.yarnpkg.com/react-native-svg-transformer/-/react-native-svg-transformer-1.0.0.tgz#7a707e5e95d20321b5f3dcfd0c3c8762ebd0221b"
Expand Down