For a specific page, I'm trying to hide the statusbar and make the content fullscreen but it doesn't seem to work.
general setting in appcomponent.ts .
//for most pages
if (core.isPlatform(OsType.CORDOVA)) {
this.statusBar.styleLightContent();
this.statusBar.overlaysWebView(false);
this.statusBar.backgroundColorByHexString('#0076b2');
}
code in specific page:
some-page.ts
//for specific page
ionViewDidLoad() {
if (this.core.isPlatform(OsType.CORDOVA)) {
this.statusBar.hide();
this.statusBar.overlaysWebView(true);
}
}
ionViewWillLeave() {
if (this.core.isPlatform(OsType.CORDOVA)) {
this.statusBar.show();
this.statusBar.overlaysWebView(false);
}
}
my result is always with the blue Statusbar visible:
Related
I am building a ride sharing app to learn react-native. In order to publish a new Ride, I have a Modal which renders conditionaly on the step state and each step has a diferente UI. Like:
let screen;
if (step===1){
ecraStep=<Screen1/>
} if (step===2){
ecraStep=<Screen2/>
} ...
On step=1 (which is the initial value) I want the callBack button to close the Modal and whenever step>1 I want it to call the following function:
function togglePreviousStep() {
setStep(step-1);
};
Which is essentially going back to the last rendered screen. I have tried it by writting this inside the Modal function component:
useFocusEffect(
React.useCallback(() => {
const onBackPress = () => {
if (step>1) {
togglePreviousStep();
return true;
} else if (step===1) {
props.closeModal();
return false;
}
};
BackHandler.addEventListener('hardwareBackPress', onBackPress);
return () =>
BackHandler.removeEventListener('hardwareBackPress', onBackPress);
}, [step, togglePreviousStep])
);
However, no matter the step state, whenever I press the backButton it closes the Modal. I don't understand what I am doing wrong.
EDITED
I implemented the Modal from react-native-modal. I used the prop onBackButtonPress like this:
<Modal
onBackButtonPress={props.onBackButtonPress}
visible={showModal}
//...
>
<NewRidesModal
//...
/>
</Modal>
And inside the Modal Screen I wrote:
if (step===1) {
onBackPressButton=(() => props.closeModal());
} else if (step>1){
onBackPressButton=(() => togglePreviousStep())
}
However, it still closes the modal when I press the android back button...
The onBackBackButtonPress is actually deprecated or removed.
Later on, I read a bit more about the modal documents on https://reactnative.dev/docs/modal#onrequestclose and I found out that:
The onRequestClose callback is called when the user taps the hardware
back button on Android or the menu button on Apple TV.
I should have investigated this before making this question. All I needed can be done with the onRequestClose prop like the following:
<Modal
onRequestClose={() => {
if (step===1) {
toggleModal();
} else if (step>1 && step<8){
togglePreviousStep();
}
}}
>
//...
</Modal>
This should work. If not put all your code involved because the split piece of them is hard to connect what are you doing.
<Modal
onBackButtonPress={() => {
if (step===1) {
props.closeModal();
} else if (step>1){
togglePreviousStep()
}
}}
visible={showModal}
//...
>
<NewRidesModal
//...
/>
</Modal>
I have created an extension for VSC that adds some statusbar buttons when a file of type JS/TS is opened. But I would rather only show the buttons if the active tab is JS/TS. Currently if I open a markdown file and a JS file the status bar buttons are added even when the MD file is the active tab.
Is there some kind of event that gets called when users swap tabs that I could use to show/hide my buttons.
Here is my repo:
https://github.com/sketchbuch/vsc_quokka_statusbar
Changing active text editor event
vscode.window.onDidChangeActiveTextEditor(editor => {
if (!editor) {
// hide
return;
}
if (editor.document.languageId === 'javascript' || editor.document.languageId === 'typescript') {
// show
} else {
// hide
}
});
If you want to consider all visible editors (split/grid):
vscode.window.onDidChangeVisibleTextEditors(editors => {
if (editors.some(editor => {
return editor.document.languageId === 'javascript' || editor.document.languageId === 'typescript';
})) {
// show
} else {
// hide
}
});
What should happen when users click over back button of phone? In case when modal opens.
Registered a back button:
// To prevent interference with ionic's own backbutton handling
// you can subscribe with a low priority instead
this.platform.backButton.subscribe(() => {
// code that is executed when the user pressed the back button
// and ionic doesn't already know what to do (close modals etc...)
self.modalController.dismiss();
});
The problem with the code:
It closes/dismiss modal is fine!
But it also pushed back the page from where the modal is opened. Means it pop the page behind modal.
This should not happen the page should not pop - only modal should close.
Check the image gif added ->
Click here to see the problem
You may consider using platform.backButton.subscribeWithPriority() with a high priority (ex: 9999).
Then checking if there is a opened modal with modalController.getTop().
constructor(private modalCtrl: ModalController, private nav: NavController) {
}
ngOnInit() {
this.platform.backButton.subscribeWithPriority(9999, () => {
this.closeModalOrPage();
});
}
async closeModalOrPage(){
let modal = await this.modalCtrl.getTop();
if (modal){
modal.dismiss();
} else {
this.nav.pop();
}
}
In Ionic 3 application, I want to show the cancel button of ion-searchbar until the search bar has value.
Mine is a tab based application and on moving to other tab and coming back to the tab, the search text is been retained and I need the cancel button also to be visible if text exists in search bar. But it is not visible.
<ion-searchbar
#projectsearchbar name="query" (search)="doSearch($event)" [(ngModel)]="global.SearchFilter" [showCancelButton]="true" cancelButtonText="Cancel" placeholder="Search" (ionCancel)="onSearchCancel($event)" (ionInput)="onInput($event)" (ionBlur)="onInputBlur()" (ionFocus)="onInputFocus()" (ionClear)="onInputClear($event)" >
I tried to get the cancel element and set the style, but it didn't work
ionViewWillEnter() {
if (this.global.SearchFilter) {
let cancelBlurElement = <HTMLElement>document.querySelector(".searchbar-ios .searchbar-ios-cancel");
cancelBlurElement.style.display = 'block';
}
}
Also tried to get the search bar control by class name and added a custom class but it didn't worked.
ionViewWillEnter() {
if (this.global.projectSearchFilter) {
let el=document.getElementsByTagName('ion-searchbar');
el[0].classList.add('visible-cancel');
}
}
.visible-cancel {
display: block!important;
}
Also tried to import as view child,
import { Component, Output, NgZone, ViewChild } from '#angular/core';
export class SearchPage {
#ViewChild('projectsearchbar') searchbar:Searchbar;
ionViewWillEnter() {
this.searchbar.setFocus();
}
}
i had the same issue
resolved by using this CSS snippet in the encapsulating element
.encapsulating-element {
.searchbar-ios-cancel{
display: none !important;
}
}
I have created a Button with the Tiny Method addButton().
How is it possible to toggle the State of the Button ?
In my first simple case I have a Button with Fullscreen
(Different Functionality than the built-in function)
and want to hide it after getting the Fullscreen State
and replace it with an "End Fullscreen" Button.
But I have not found the right way to show or hide them.
I know that the button will get an ID, but I dont know which one ...
If you add the button with:
editor.addButton('customFullscreen', {
tooltip: 'Fullscreen',
shortcut: 'Ctrl+Alt+F',
onClick: toggleCustomFullscreen,
onPostRender: function() {
var self = this;
editor.on('CustomFullscreenStateChanged', function(e) {
if (e.state) {
self.name('Close fullscreen');
//self.active(e.state); // uncomment for "pressed" look
} else {
self.name('Fullscreen');
}
});
}
});
and handle the event with
var customFullscreenState = false;
function toggleFullscreen() {
customFullscreenState = !customFullscreenState;
if (customFullscreenState) {
// do something, we are active
} else {
// do something else, we're unactive
}
editor.fire('CustomFullscreenStateChanged', {state: fullscreenState});
}
You should be able to have it look like wo different button and do two different things depending on state, but it will still just be one button that changes action and text.