-
Notifications
You must be signed in to change notification settings - Fork 25
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
VBLOCKS-2485: Changes needed due to refactor of react native sdk #129
Changes from 10 commits
153f152
530019c
2ff3a28
8a4dcc0
9390d23
451419f
7fd8f2b
b6a1d68
6760baa
4492a23
9177339
740a0bb
74041f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,37 +3,58 @@ | |
import com.facebook.react.ReactActivity; | ||
import com.facebook.react.ReactActivityDelegate; | ||
import com.facebook.react.ReactRootView; | ||
import com.twiliovoicereactnative.VoiceActivityProxy; | ||
|
||
import android.Manifest; | ||
import android.content.pm.PackageManager; | ||
import android.content.Intent; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.Window; | ||
import android.view.WindowManager; | ||
|
||
import androidx.core.app.ActivityCompat; | ||
import androidx.core.content.ContextCompat; | ||
import android.widget.Toast; | ||
|
||
public class MainActivity extends ReactActivity { | ||
private static final String TAG = "MainActivity"; | ||
private static final int MIC_PERMISSION_REQUEST_CODE = 1; | ||
public static class MainActivityDelegate extends ReactActivityDelegate { | ||
public MainActivityDelegate(ReactActivity activity, String mainComponentName) { | ||
super(activity, mainComponentName); | ||
} | ||
|
||
private boolean checkPermissionForMicrophone() { | ||
int resultMic = ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO); | ||
return resultMic == PackageManager.PERMISSION_GRANTED; | ||
} | ||
@Override | ||
protected ReactRootView createRootView() { | ||
ReactRootView reactRootView = new ReactRootView(getContext()); | ||
// If you opted-in for the New Architecture, we enable the Fabric Renderer. | ||
reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED); | ||
return reactRootView; | ||
} | ||
|
||
private void requestPermissionForMicrophone() { | ||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.RECORD_AUDIO)) { | ||
Log.d(TAG, "Microphone permissions needed. Please allow in your application settings."); | ||
} else { | ||
ActivityCompat.requestPermissions( | ||
this, | ||
new String[]{Manifest.permission.RECORD_AUDIO}, | ||
MIC_PERMISSION_REQUEST_CODE); | ||
@Override | ||
protected boolean isConcurrentRootEnabled() { | ||
// If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18). | ||
// More on this on https://reactjs.org/blog/2022/03/29/react-v18.html | ||
return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; | ||
} | ||
} | ||
|
||
private final VoiceActivityProxy activityProxy = new VoiceActivityProxy( | ||
this, | ||
permission -> { | ||
if (Manifest.permission.RECORD_AUDIO.equals(permission)) { | ||
Toast.makeText( | ||
MainActivity.this, | ||
"Microphone permissions needed. Please allow in your application settings.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Android doesn't automatically give these prompts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope, it only places a system pop-up when you request permissions.... but they can always disable it later from the system menus. |
||
Toast.LENGTH_LONG).show(); | ||
} else if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) && | ||
Manifest.permission.BLUETOOTH_CONNECT.equals(permission)) { | ||
Toast.makeText( | ||
MainActivity.this, | ||
"Bluetooth permissions needed. Please allow in your application settings.", | ||
Toast.LENGTH_LONG).show(); | ||
} else if ((Build.VERSION.SDK_INT > Build.VERSION_CODES.S_V2) && | ||
Manifest.permission.POST_NOTIFICATIONS.equals(permission)) { | ||
Toast.makeText( | ||
MainActivity.this, | ||
"Notification permissions needed. Please allow in your application settings.", | ||
Toast.LENGTH_LONG).show(); | ||
} | ||
}); | ||
/** | ||
* Returns the name of the main component registered from JavaScript. This is used to schedule | ||
* rendering of the component. | ||
|
@@ -56,30 +77,18 @@ protected ReactActivityDelegate createReactActivityDelegate() { | |
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
if (!checkPermissionForMicrophone()) { | ||
requestPermissionForMicrophone(); | ||
} | ||
activityProxy.onCreate(savedInstanceState); | ||
} | ||
|
||
public static class MainActivityDelegate extends ReactActivityDelegate { | ||
public MainActivityDelegate(ReactActivity activity, String mainComponentName) { | ||
super(activity, mainComponentName); | ||
} | ||
|
||
@Override | ||
protected ReactRootView createRootView() { | ||
ReactRootView reactRootView = new ReactRootView(getContext()); | ||
// If you opted-in for the New Architecture, we enable the Fabric Renderer. | ||
reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED); | ||
return reactRootView; | ||
} | ||
@Override | ||
public void onDestroy() { | ||
activityProxy.onDestroy(); | ||
super.onDestroy(); | ||
} | ||
|
||
@Override | ||
protected boolean isConcurrentRootEnabled() { | ||
// If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18). | ||
// More on this on https://reactjs.org/blog/2022/03/29/react-v18.html | ||
return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; | ||
} | ||
@Override | ||
public void onNewIntent(Intent intent) { | ||
super.onNewIntent(intent); | ||
activityProxy.onNewIntent(intent); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarifying Question: Will users who just use the SDK also need to make these changes in their React Native Apps?
I.E: users not using the reference app, but using the sdk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but we are still in beta, and it will make customers lives easier down the line... because we abstract much of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like these changes will be included in
beta.4
, could we have a guide to updating tobeta.4
for users who are onbeta.3
and below?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mhuynh5757 https://issues.corp.twilio.com/browse/VBLOCKS-2556 has been created