Get anchors to fill remaining area in the parent - qml

I have a QML component called MyComponent and I have the following instantiations:
MyComponent {
id: rightComponent
SettingsScreenHeader {
id: settingsHeader
}
SettingsScreen {
id: settingsScreen
}
StackView {
id: settingsStack
anchors.fill: parent
initialItem: settingsScreen
}
}
SettingsScreenHeader and SettingsScreen are two other components. At the moment when I do anchors.fill: parent in the StackView object, it takes all the space and the header object gets obscured. Is there a way to tell it to fill all the remaining space in the parent?

Try using ColumnLayout:
MyComponent {
id: rightComponent
ColumnLayout {
anchors.fill: parent
SettingsScreenHeader {
id: settingsHeader
Layout.fillWidth: true
}
SettingsScreen {
id: settingsScreen
Layout.fillWidth: true
}
StackView {
id: settingsStack
Layout.fillHeight: true
Layout.fillWidth: true
initialItem: settingsScreen
}
}
}
See the documentation for further details.

Related

How to program TopBar button press event handler?

I'm using Wix's react-native-navigation.
their documentation says a component can listen to topper buttons events by using Navigation.events().bindComponent(this); as well as navigationButtonPressed({ buttonId }) {
// will be called when "buttonOne" is clicked
}
however nothing is happening. not even the original pop event.
export default class Lobby extends React.Component {
static options(passProps) {
topBar: {
title: {
text: "Lobby"
},
visible: true,
leftButtons: [
{
id: "testId",
text: "Leave",
color:"red"
}
]
}
}
constructor(props) {
super(props);
Navigation.events().bindComponent(this);
}
navigationButtonPressed({ buttonId }) {
switch(buttonId) {
case: "testId":
alert("test");
socket.emit("disconnect");
break;
}
}
Navigation is imported successfully.
I expect at least, the socket event to be received by the server, I also want the page to be popped and Navigated to previous page.
the alert displays, but no server event is received at all.
I had the same blocker and this is how I fixed it. I used registerNavigationButtonPressedListener() and passed navigationButtonPressed
`constructor(props) {
super(props);
Navigation.events().registerNavigationButtonPressedListener(this.navigationButtonPressed);
}
navigationButtonPressed({ buttonId }) {
switch(buttonId) {
case: "testId":
alert("test");
socket.emit("disconnect");
break;
}`

Navigation using 'react-native-navigation'

I have created app using 'react-native-navigation' and first navigation working fine.
Navigation.startSingleScreenApp({
screen: {
screen: 'drawer.HomeScreen',
title: '',
navigatorStyle: {
navBarHidden: true
}
}
});
I got issue in navigation
import { Navigation } from 'react-native-navigation';
and tried to navigate using
Navigation.push({
component: {
name: 'drawer.DashboardScreen'
}
});
startMainTab.js
const startTabs = () => {
Promise.all([
Icon.getImageSource("ios-share-alt", 30),
Icon.getImageSource("ios-menu", 30)
]).then(sources => {
Navigation.startTabBasedApp({
tabs: [{
screen: 'drawer.AnalyticsScreen',
navigatorButtons: {
leftButtons: [{
icon: sources[1],
title: "Menu",
id: 'sideDrawerToggle'
}]
}
},
{
screen: 'drawer.DashboardScreen',
navigatorButtons: {
leftButtons: [{
icon: sources[1],
title: "Menu",
id: 'sideDrawerToggle'
}]
}
}
],
drawer: {
left: {
screen: 'drawer.SideDrawer'
}
}
});
});
}
SideDrawer.js
export default startTabs;
export default class SideDrawer extends Component {
constructor(props) {
super(props);
this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent);
}
componentWillMount() {
this.props.navigator.setOnNavigatorEvent(this.onNavigationEvent)
}
onNavigationEvent = (event) => {
// handle a deep link
if (event.type == 'DeepLink') {
const parts = event.link;
alert("Scree: " + parts)
//this.navigateToAbout()
this.props.navigator.push({
screen: "drawer.HomeScreen"
})
if (parts == 'drawer.DashboardScreen') {
//this.onPressScreen1();
}
}
}
navigateToAbout = () => {
this.props.navigator.push({
screen: 'drawer.DashboardScreen'
})
}
render() {
return ( <
View style = {
styles.container
} >
<
Text > SideDrawer < /Text> <
TouchableHighlight onPress = {
this.navigateToAbout.bind(this)
} >
<
Text > Click Me < /Text> <
/TouchableHighlight> <
/View>
)
}
}
Since pushing a screen is an action you perform on an existing navigation stack, you need to call it on your current component navigator object which you'll automagically get as a prop:
this.props.navigator.push({screen: 'drawer.DashboardScreen'})
I strongly suggest you migrate to react-native-navigation v2 as v1 has limited functionality and is no longer maintained.
Download source code from here(React Native Navigation)
App.js:
import React, {Component} from 'react';
import {createStackNavigator,createAppContainer} from 'react-navigation'
import HomeScreen from './Screens/HomeScreen';
import ProfileScreen from './Screens/ProfileScreen';
import ContactScreen from './Screens/ContactScreen';
import MainScreen from './Screens/MainScreen'
export default class App extends Component {
render() {
return <AppNavigationContainer/>
}
}
const AppNavigator = createStackNavigator({
Main:MainScreen,
Home: HomeScreen,
Profile: ProfileScreen,
Contact:ContactScreen
}, {
initialRouteName: 'Main',
navigationOptions: {
headerTitleStyle: {
fontWeight: "bold",
color: "red",
},
headerTintColor: "red"
}
})
const AppNavigationContainer = createAppContainer(AppNavigator);
MOVE FROM ONE SCREEN TO ANOTHER:
this.props.navigation.navigate('Profile')
Thanks!

How to hide tabBar from a child stack to parent stack navigator?

I have a screen 'About' which doesn't need a tabBar but other siblings to that screen must have tabBar.
the third element in the tab named 'Settings' have a default class in which i used a stack navigator.
export default class Setting extends Component {
constructor(props) {
super(props);
this.state = {
}
}
static navigationOptions = {
header: null,
tabBarVisible:true // if i place false here the tabBar is invisible on all screens in below specified stack.
};
render() {
return (
<SettingStack />
);
}
}
export const SettingStack = StackNavigator({
// screenname : { screen : ImportedClassname }
settingsscreen: { screen: SettingsScreen },
first: { screen: first },
second: { screen: second },
about: { screen: About },
third: { screen: third },
});
How can i hide the tabBar only on 'about' screen .
just remove the default export class and use that "settingstack" in your parent navigation tree. it will work for sure if not please get back...

Angular2 Component listen when parent's resize change

I have a requirement in which I want to change properties of a child component depending on the size of its parent component though a method call. The issue I am running into is that the only resize event I can listen to is that of the window, which doesn't help as the window size is not changing, only the parent component is due to a side panel div opening and closing.
The only possibility I can see at the moment is to have some sort of polling in which we within the child component itself that checks if its width has changed every x amount of time.
Thanks for your help!
You are correct that you can't get the resize event on a div (without installing some js extension). But something like this works.
The Parent Component:
import {Component, AfterContentInit, ElementRef} from '#angular/core';
import { ChildComponent } from "./ChildComponent";
export interface IParentProps {
width: number;
height: number;
}
#Component({
selector: 'theParent',
template: `text text text text text text
text text text text text text
<the-child [parentProps]="parentProps"></the-child>`,
directives: [ChildComponent]
})
export class ParentComponent implements AfterContentInit {
sizeCheckInterval = null;
parentProps: IParentProps = {
width: 0,
height: 0
}
constructor(private el: ElementRef) {
}
ngAfterContentInit() {
this.sizeCheckInterval = setInterval(() => {
let h = this.el.nativeElement.offsetHeight;
let w = this.el.nativeElement.offsetWidth;
if ((h !== this.parentProps.height) || (w !== this.parentProps.width)) {
this.parentProps = {
width: w,
height: h
}
}
}, 100);
}
ngOnDestroy() {
if (this.sizeCheckInterval !== null) {
clearInterval(this.sizeCheckInterval);
}
}
}
The Child Component:
import {Component, Input, SimpleChange} from "#angular/core";
import { IParentProps } from "./ParentComponent";
#Component({
directives: [],
selector: "the-child",
template: `child`
})
export class ChildComponent {
#Input() parentProps: IParentProps;
constructor() {
this.parentProps = {
width: 0,
height: 0
}
}
ngOnChanges(changes: { [propName: string]: SimpleChange }) {
this.parentProps = changes["parentProps"].currentValue;
console.log("parent dims changed");
}
}

Create a component as a member in an object instance

I have a QML component called MyComponent and I have an instance of it as follows:
MyComponent {
id: rightComponent
property Component settingsScreen: SettingsScreen {}
StackView {
id: settingsStack
anchors.fill: parent
initialItem: rightComponent.settingsScreen
}
}
SettingsScreen is another component that I have. The problem is that it does not seem that rightComponent is the parent of settingsScreen. I get the correct result when I embed as:
MyComponent {
id: rightComponent
SettingsScreen {}
}
This is fine and everything is laid out correctly.
You can solve as it follows:
MyComponent {
id: rightComponent
SettingsScreen {
id: settingsScreen
}
StackView {
id: settingsStack
anchors.fill: parent
initialItem: settingsScreen
}
}
There is no need to define a new property as you did.